日期:2014-05-18 浏览次数:20874 次
select a,max(b) as mb from ta order by max(b)
------解决方案--------------------
declare @tb table (a nvarchar(12),b int) insert @tb select '我',1 union all select '我',2 union all select '你',3 union all select '他',4 union all select '她',5 union all select '她',6 select a from ( select top (100) ROW_NUMBER() over(PARTITION by a order by a desc)rn ,a,b from @tb group by a,b order by b desc) aa where rn=1 /* a 她 他 你 我 */
------解决方案--------------------
select a from ta group by a order by max(b) desc
------解决方案--------------------
CREATE TABLE tmp AS SELECT MIN(b) as id FROM ta GROUP BY a;
DELETE FROM ta WHERE id NOT IN (SELECT id FROM tmp )
DROP TABLE tmp
然后 select * from ta order by b desc
------解决方案--------------------
select a,max(b)
from ta
group by a
order by b desc
酱紫不可以吗?
------解决方案--------------------
distinct
------解决方案--------------------
CREATE TABLE TEST2 ( Name VARCHAR(10), Id INT ) GO INSERT INTO TEST2 SELECT '我',1 UNION SELECT '我',2 UNION SELECT '你',3 UNION SELECT '他',4 UNION SELECT '她',5 UNION SELECT '她',6 SELECT NAME FROM TEST2 GROUP BY Name ORDER BY MAX(ID) DESC
------解决方案--------------------
distinct
------解决方案--------------------
select top 10 a from( select distinct a,max(b) as b from ta group by b) table_A order by b desc
------解决方案--------------------