我想用某一个字段a排序,但是我的SQL语句包含distinct,在distinct的时候不想把字段a给列进去
sqlserver:SQL语句
我想用某一个字段a排序,也就是order by a
但是我的SQL语句包含distinct,在distinct的时候不想把字段a给列进去。
应该怎么实现。
语句如下:
select distinct b,c from table order by a desc(这样肯定会报错的,因为a在order by 里,而且语句还包含distince,a就必须出现在select中)
[解决办法]
SELECT B,C FROM TB GROUP BY B,C ORDER BY MIN(A)
TRY
[解决办法]
select b,c,min(a) a from tbgroup by b,corder by a desc
[解决办法]
declare @t table (b int,c int,a int)insert into @tselect 1,1,4 union allselect 1,1,2 union allselect 2,2,3 union allselect 3,3,6 union allselect 2,2,5 union allselect 3,3,1SELECT distinct b,c from @t/*b c----------- -----------1 12 23 3*/