数据库 sql

查询比例 近一年的数据 分组查询

SELECT
	t1.pc_handling_guideline_suggestion_satisfaction satisfaction,
	ROUND(
		COUNT(
			t1.pc_handling_guideline_suggestion_id
		) * 100 / (
			SELECT
				COUNT(1)
			FROM
				t_portal_pc_handling_guideline_suggestion a,
				t_portal_pc_handling_guideline b
			WHERE
				a.pc_handling_guideline_suggestion_guideline_code = b.portal_pc_handling_guideline_code
			AND a.pc_handling_guideline_suggestion_state = 1
			AND DATE_FORMAT(
				a.pc_handling_guideline_suggestion_time,
				'%Y-%m-%d'
			) >= DATE_FORMAT(
				DATE_ADD(NOW(), INTERVAL - 1 YEAR),
				'%Y-%m-%d'
			)
		),
		2
	)
VALUE
FROM
	t_portal_pc_handling_guideline_suggestion t1,
	t_portal_pc_handling_guideline t2
WHERE
	t1.pc_handling_guideline_suggestion_guideline_code = t2.portal_pc_handling_guideline_code
AND t1.pc_handling_guideline_suggestion_state = 1
AND DATE_FORMAT(
	t1.pc_handling_guideline_suggestion_time,
	'%Y-%m-%d'
) >= DATE_FORMAT(
	DATE_ADD(NOW(), INTERVAL - 1 YEAR),
	'%Y-%m-%d'
)
AND t1.pc_handling_guideline_suggestion_satisfaction != '1'
GROUP BY
	t1.pc_handling_guideline_suggestion_satisfaction

-- 5非常满意 4满意 3基本满意 2不满意 1非常不满

在这里插入图片描述
查询没有主体的事项


-- 统计没有主题的事项
select 
	g.portal_pc_handling_guideline_code as '事项code',
	g.portal_pc_handling_guideline_name as '事项名称',
	gs.pc_guideline_scene_name as '主题名称'
from t_portal_pc_handling_guideline g 
left join t_portal_pc_guideline_scene_guideline gsg on gsg.pc_guideline_scene_guideline_guideline_id = g.portal_pc_handling_guideline_id
left join t_portal_pc_guideline_scene gs on gsg.pc_guideline_scene_guideline_scene_code = gs.pc_guideline_scene_code
where g.portal_pc_handling_guideline_state != 99 and (gs.pc_guideline_scene_name is null or gs.pc_guideline_scene_name = '')
group by g.portal_pc_handling_guideline_id

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值