mysql查询

时间:2022-01-06 18:29:10

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