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

mysql查询

时间:2020-02-06 16:27:56      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:ike   收入   null   sele   mys   查询   time   when   count   

1.示例1

查询1:

SELECT CASE main_xm_sam31 WHEN ‘02‘ THEN 2 ELSE 1 END AS SPDJ FROM SR_MAIN_BG A WHERE A.PK_SR_MAIN = ‘1162275825622593536‘ AND (SYS_SPDJ = 0 OR SYS_SPDJ = -1)

查询2:

SELECT
count(1) AS ncount,
(
CASE sys_sjbj
WHEN 0 THEN
‘个人发布‘
WHEN 1 THEN
‘组织发布‘
WHEN 2 THEN
‘机构发布‘
ELSE
‘其他‘
END
) AS fblx,
ifnull(
sum(CASE rlzt WHEN 2 THEN 1 ELSE 0 END),
0
) AS xyl,
ifnull(
ROUND(
sum(
TIMESTAMPDIFF(DAY, fbsj, rlsj)
) / sum(CASE rlzt WHEN 2 THEN 1 ELSE 0 END),
1
),
0
) AS pjrlsj
FROM
sr_xqfb
WHERE
fbrq LIKE ‘2019%‘
GROUP BY
sys_sjbj

查询3:

SELECT
CASE WHEN mdjlx = ‘0301‘ THEN ‘人道救援‘ 
WHEN mdjlx = ‘2201‘ THEN ‘低收入家庭免费用电信息‘
WHEN mdjlx = ‘2301‘ THEN ‘低收入家庭优待信息‘
ELSE ‘暂定-农办厅专项救助‘ END AS mdjlx,
sys_xzqh
from sr_main_zdts

mysql查询

标签:ike   收入   null   sele   mys   查询   time   when   count   

原文地址:https://www.cnblogs.com/tongcc/p/12269015.html

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