锦绣未央网络首播量:sql 高手进!(解决后再给分!!)

来源:百度文库 编辑:中科新闻网 时间:2024/05/03 16:47:07
有个表,里面有字段 numb, time
现在我需要通过一个查询,实现下面的显示结果
1,将 numb = 1 的记录显示在前面 并且 按 time 排序
2,将 unmb <> 1 的记录显示在后面, 并且 按 time 排序
1 楼的好象不行啊,union前面不能用order by 的!!!

对! Union 不能和order by 共用

但是可以用子查询 实现:

select * from (select * from tablename where numb=1 order by time) as a
UNION ALL
select * form (select * from tablename where numb<>1 order by time) as b;

二。 如果numb列中 1 是最小的 可以使用 多条件排序:

select * from tablename order by numb,time

三。还能使用 case 语句(各个数据库语法不同,看你是什么数据库?)

============================有事发我消息===========

select * from tablename where numb=1 order by time
UNION ALL
select * from tablename where numb<> order by time

同意楼上的
帮他接分的