从结果查询中选择count(*)

编程入门 行业动态 更新时间:2024-10-11 21:32:25
本文介绍了从结果查询中选择count(*)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要您的帮助,这是我的SQL查询:

I need help from you, this is my sql query:

select count(SID) from Test where Date = '2012-12-10' group by SID

这是我的结果:

|2| |3| |4| |3|

现在我必须计算第一个查询的结果!

and now I have to count the results from first query!

Expected result: 4

推荐答案

您可以将查询包装在另一个SELECT中:

You can wrap your query in another SELECT:

select count(*) from ( select count(SID) tot -- add alias from Test where Date = '2012-12-10' group by SID ) src; -- add alias

请参见带有演示的SQL小提琴

为使其正常工作,count(SID)需要一个列别名,并且您必须为子查询本身提供一个别名.

In order for it to work, the count(SID) need a column alias and you have to provide an alias to the subquery itself.

更多推荐

从结果查询中选择count(*)

本文发布于:2023-11-22 02:21:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615594.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:count

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!