日期:2014-05-18 浏览次数:20464 次
select b.* from b join a on b.序号=a.默认厂商 order by a.序号 -- try
------解决方案--------------------
[code=SQL] CREATE TABLE t1 ( xuhao INT, name INT ) INSERT INTO t1 SELECT 1, 2 CREATE TABLE t2 ( xuhao INT, name VARCHAR(10) ) INSERT INTO t2 SELECT 1, '奔驰' UNION ALL SELECT 2, '宝马' UNION ALL SELECT 3, '丰田' SELECT * FROM t1 SELECT * FROM t2 SELECT * FROM t2 LEFT JOIN t1 ON t2.xuhao=t1.NAME ORDER BY CASE WHEN t1.xuhao IS NOT NULL THEN 0 ELSE 1 END ------------------------ xuhao name xuhao name 2 宝马 1 2 3 丰田 NULL NULL 1 奔驰 NULL NULL
------解决方案--------------------
select b.* from b left join a on b.序号=a.默认厂商 order by case when a.序号 is not null then 1 else 2 end,b.序号