5 回答
TA贡献1982条经验 获得超2个赞
可以使用row_number()函数,该函数可以将相同的数据做归类,并附加一列,作为序数列,sql如下:
select *,ROW_NUMBER() over (partition by address order by age desc) as rw
from stu;
只要在该查询结果集外再嵌套一个取出rw=1的sql语句即可,如下:
select * from (
select *,ROW_NUMBER() over (partition by address order by age desc) as rw
from stu ) as t1
where rw = 1;
TA贡献1786条经验 获得超13个赞
三个字段不重复值的数量可能不一样,所以不能将它们放在同一个表里。
你可以分别用三个语句获取它们不重复的值列表。
select distinct address from stu;
select distinct name from stu;
select distinct age from stu;
TA贡献1820条经验 获得超9个赞
elect address,name,age from stu a
where name+age=(select top 1 name+age from stu where a.address=address group by name,age)
TA贡献1853条经验 获得超9个赞
select address,name,age from stu where (address,age) in(select address,max(age) from stu group by address)
- 5 回答
- 0 关注
- 377 浏览
添加回答
举报