我需要很少的要求,我有以下输入。
ReportId ReportName
1 Adhoc
1 Adhoc
2 Financial
2 Financial
2 Financial
3 Dynamic
3 Dynamic
3 Dynamic
3 Dynamic
我需要像这样放
ReportId ReportName
2 Adhoc
3 Financial
4 Adhoc
请给我解决方案
答案 0 :(得分:1)
select count(*),reportname from tbl group by reportname;
答案 1 :(得分:0)
select count(ReportName) as howMany, ReportName
from reports
group by ReportName
order by howMany asc
答案 2 :(得分:0)
如果您在第一栏中寻找计数,那么这将有所帮助:
SELECT Count(ReportName), ReportName FROM Table1 group by ReportName
答案 3 :(得分:0)
我认为你在你想要输出的问题中错误地提到了这个。
ReportId ReportName
2 Adhoc
3 Financial
4 Dynamic
以下查询将为您提供上述输出。
select Reportname, count(1) as ReportIdcount
from Reportstb
group by reportname;