查询出荣誉表的类型大于2的所有老师id

查询出荣誉表的类型大于2的所有老师id_第1张图片
语句

SELECT  DISTINCT
	a.teacher_id,
a.type
FROM
	sta_sci_paper a
JOIN
	(
		SELECT
			type
		FROM
			sta_sci_paper
		GROUP BY type
		HAVING COUNT(type) >4
AND
	type='1'
	) b
ON
	a.type = b.type;

查询出荣誉表的类型大于2的所有老师id_第2张图片

SELECT DISTINCT
				a.teacher_id 
			FROM
				sta_sci_paper a
			JOIN (
				SELECT
					teacher_id
				FROM
					sta_sci_paper
				GROUP BY
					teacher_id
				HAVING
					COUNT(teacher_id) > 4 AND COUNT(type) > 3
			) b ON a.teacher_id = b.teacher_id

查询出荣誉表的类型大于2的所有老师id_第3张图片
在这里插入图片描述

你可能感兴趣的:(sql题库,项目碎片——sql)