sql语句 按所在城市分类,查询哪个城市的学生最多

2025-03-04 15:12:49
推荐回答(2个)
回答1:

您好:

语句如下,请自行测试。。。

SELECT TOP 1 城市,COUNT(*) AS c
  FROM 学生表
 GROUP BY 城市
 ORDER BY c DESC

回答2:

create procedure pro_author(@author char(20))
as
select *
from 表名
where author=@author
order by 所在城市 asc,作者编号 desc

declare @writer char(20)
set @writer='作者姓名'
exec pro_author @writer