首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

小弟我想用某一个字段a排序,但是小弟我的SQL语句包含distinct,在distinct的时候不想把字段a给列进去

2012-03-22 
我想用某一个字段a排序,但是我的SQL语句包含distinct,在distinct的时候不想把字段a给列进去sqlserver:SQL

我想用某一个字段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
[解决办法]

SQL code
select b,c,min(a) a from tbgroup by b,corder by a desc
[解决办法]
SQL code
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*/ 

热点排行