日期:2014-05-18  浏览次数:20485 次

两张表排序问题
A表:
ID Name total
1 apple 6
2 peach 1 
3 banana 2

B表:
ID Name
1 banana

若b表中包含a表中的项目,
则将该项排在前面,再按照a表中的total的数量排序。

结果:
3 banana 2
1 apple 6
2 peach 1 



------解决方案--------------------
select a.* from a order by case when exists(select 1 from b where b.name = a.name) then 1 else 2 end , a. total desc