+ -
当前位置:首页 → 问答吧 → sql

sql

时间:2011-11-09

来源:互联网

northwind中怎么查城市人数最多的城市名和城市ID

作者: lyb438301070   发布时间: 2011-11-09

SQL code
select count(city),id from 
tb

作者: lzd_83   发布时间: 2011-11-09

SQL code
select max(count(city)),id
from tb

作者: lzd_83   发布时间: 2011-11-09

SQL code

select top 1 count(城市名),城市ID 
from tb 
group by 城市ID 
order by count(城市名) desc

作者: chtzhking   发布时间: 2011-11-09

SQL code
select 城市名,ID from tb t where 人数=(select max(人数) from tb where id=t.id)

作者: fredrickhu   发布时间: 2011-11-09

SQL code
use northwind
go


SELECT city ,COUNT(customerid) AS 人数
FROM dbo.Customers 
GROUP BY city
ORDER BY COUNT(customerid) desc

作者: OrchidCat   发布时间: 2011-11-09

SQL code

select top 1 city,count(1) from customers group by city order by count(1) desc

作者: pengxuan   发布时间: 2011-11-09