有如下数据表:
Table: [student]
ID Name Score
1 chris 100
2 linda 80
3 jack 90
4 andy 80
5 harry 70现在用SELECT语句进行查询:
select * from student where score>70 order by ID asc;
结果如下:
1 chris 100
2 linda 80
3 jack 90
4 andy 80
如果要求有所变化,还要对结果集进行二次排序,以score为索引:
那么语句写成select * from student where score>70 order by ID asc,score asc
如果仍然是
1 chris 100
2 linda 80
3 jack 90
4 andy 80
而我想要的结果是
1 chris 100
3 jack 90
2 linda 80
4 andy 80
请问SQL语句该如何写???
Table: [student]
ID Name Score
1 chris 100
2 linda 80
3 jack 90
4 andy 80
5 harry 70现在用SELECT语句进行查询:
select * from student where score>70 order by ID asc;
结果如下:
1 chris 100
2 linda 80
3 jack 90
4 andy 80
如果要求有所变化,还要对结果集进行二次排序,以score为索引:
那么语句写成select * from student where score>70 order by ID asc,score asc
如果仍然是
1 chris 100
2 linda 80
3 jack 90
4 andy 80
而我想要的结果是
1 chris 100
3 jack 90
2 linda 80
4 andy 80
请问SQL语句该如何写???
倒过来后结果集就不一样了,就是说要在已有的结果集上用score作索引进行二次排序,如果数据量很多,颠倒order by子句的列名后会产生完全不同的结果集,这里结果集要保持不变的。