码迷,mamicode.com
首页 > 数据库 > 详细

模糊查询--视图写sql

时间:2018-04-18 21:55:27      阅读:523      评论:0      收藏:0      [点我收藏+]

标签:新项目   join   审核   main   视图   字段名   when   属性   模糊   

《1》cip_admin_domain(option字段A)  ---> 里面配置(option字段A)属性,defalut_value设置初始值(如:创建新项目,其创建后的项目状态为“待审核”)

         cip_admin_codes(option字段A)

         注:两个表里面的字段,和,前端页面代码《option》字段--》必须一致,

《2》多条件取值的函数,在sql中

select   

字段a,字段b

(

case 

     when (codes.字段1 = ‘option英文别名1‘)  then ‘中文名1‘

     when (codes.字段2 = ‘option英文别名2‘)  then ‘中文名2‘

     when (codes.字段3 = ‘option英文别名3‘)  then ‘中文名3‘

 

end

)as 字段a

from  table where 条件

案例:

--简单Case函数
CASE sex
         WHEN ‘1‘ THEN ‘男‘
         WHEN ‘2‘ THEN ‘女‘
ELSE ‘其他‘ END

----需要注意的问题,Case函数只返回第一个符合条件的值,剩下的Case部分将会被自动忽略。

--Case搜索函数 CASE WHEN sex = ‘1‘ THEN ‘男‘ WHEN sex = ‘2‘ THEN ‘女‘ ELSE ‘其他‘ END

《3》 select 字段a,字段b,

`cod`.`code_name` AS `字段别名`,  ----list显示的中文
`cod`.`code_type` AS `字段名`,   -----前端页面传的是英文别名(codes的类型)

from 表名

LEFT JOIN `cip_admin_codes` `cod` ON (
(
(
`m`.`project_scale` = `cod`.`code_type`  
)
AND (
`cod`.`domain_id` = ‘project_scale‘
)
)
)  

注:前端页面,field list--》一定是别名

模糊查询--视图写sql

标签:新项目   join   审核   main   视图   字段名   when   属性   模糊   

原文地址:https://www.cnblogs.com/Darkqueen/p/8877721.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!