-3

我需要很小的要求,我有以下输入。

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

请给我解决方案

4

4 回答 4

1
select count(*),reportname from tbl group by reportname;
于 2012-06-07T12:54:28.000 回答
0

我认为您在问题中错误地提到了您想要这样的输出。

ReportId   ReportName
    2    Adhoc
    3    Financial
    4    Dynamic

以下查询将为您提供上述输出。

select Reportname, count(1) as ReportIdcount
from   Reportstb
group by reportname;
于 2012-06-07T13:15:00.487 回答
0
select count(ReportName) as howMany, ReportName 
from reports
group by ReportName 
order by howMany asc
于 2012-06-07T12:53:38.860 回答
0

如果您在第一列中寻找计数,那么这将有所帮助:

SELECT Count(ReportName), ReportName FROM Table1 group by ReportName
于 2012-06-07T12:57:03.577 回答