我有一个数据库如下:
现在我想获得COUNT
分类为小于或大于 5 s 和GROUP BY
Name
. 然后我需要在gridview中显示数据。
任何人都可以告诉我 SQL 命令或任何其他方法吗?
我有一个数据库如下:
现在我想获得COUNT
分类为小于或大于 5 s 和GROUP BY
Name
. 然后我需要在gridview中显示数据。
任何人都可以告诉我 SQL 命令或任何其他方法吗?
SELECT Name, COUNT(Time)
FROM MyTable
GROUP BY Name
HAVING COUNT(Time) > 5 OR COUNT(Time) < 5
或者
SELECT Name, COUNT(Time)
FROM MyTable
GROUP BY Name
HAVING COUNT(Time) <> 5
select Name, COUNT(Time)
FROM Table
GROUP BY Name
having COUNT(Time) <>5
我想你要求的是...
SELECT Name, case when time<5 then 'less' else '5 or over' end, COUNT(*)
FROM yourtable
GROUP BY Name , case when time<5 then 'less' else '5 or over' end
或作为列
select name,
SUM(case when time<5 then 1 else 0 end) as unders,
SUM(case when time>=5 then 1 else 0 end) as overs
from yourtable
group by name