日期:2014-05-16 浏览次数:20871 次
show create table 20130225t1; CREATE TABLE `20130225t1` ( `id` tinyint(4) NOT NULL AUTO_INCREMENT, `b` char(1) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB
select * from 20130225t1 order by case b when '甲' then 1 when '乙' then 2 when '丙' then 3 when '丁' then 4 end
select * from 20130225t1 order by FIND_IN_SET(b,'甲,乙,丙,丁')
show create table 20130225work CREATE TABLE `20130225work` ( `id` tinyint(4) NOT NULL AUTO_INCREMENT, `role_id` tinyint(4) NOT NULL, `dep_id` tinyint(4) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB
show create table 20130225role CREATE TABLE `20130225role` ( `id` tinyint(4) NOT NULL, `role_name` varchar(5) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB
set @role_id=1; set @dept_id=1; select * from 20130225work where role_id=@role_id and (case need_check when 1 then dep_id=@dept_id else 1=1 end)
set @role_id=2; set @dept_id=1; select * from 20130225work where role_id=@role_id and (case need_check when 1 then dep_id=@dept_id else 1=1 end)
set @role_id=1; set @dept_id=2; select * from 20130225work w,20130225role r where r.id=@role_id and w.role_id=r.id and (case need_check when 1 then dep_id=@dept_id else 1=1 end)