-
临摹微笑
可以使用row_number()函数,该函数可以将相同的数据做归类,并附加一列,作为序数列,sql如下:select *,ROW_NUMBER() over (partition by address order by age desc) as rwfrom stu;只要在该查询结果集外再嵌套一个取出rw=1的sql语句即可,如下:select * from (select *,ROW_NUMBER() over (partition by address order by age desc) as rwfrom stu ) as t1where rw = 1;
-
开满天机
三个字段不重复值的数量可能不一样,所以不能将它们放在同一个表里。你可以分别用三个语句获取它们不重复的值列表。select distinct address from stu;select distinct name from stu;select distinct age from stu;
-
千万里不及你
select address,max(name),,max(age) from stu group by address;
-
慕妹3146593
elect address,name,age from stu awhere name+age=(select top 1 name+age from stu where a.address=address group by name,age)
-
暮色呼如
select address,name,age from stu where (address,age) in(select address,max(age) from stu group by address)