mysql结果取交集_MySQL查询结果取交集的实现⽅法
destroyed_MySQL
本科毕业论文
<
1
MySQL中如何实现以下SQL查询
(SELECT S.Name
FROM STUDENT S, TRANSCRIPT T
WHERE S.StudId = T.StudId AND T.CrsCode = ‘CS305’)
INTERSECT
(SELECT S.Name
FROM STUDENT S, TRANSCRIPT T
写一个
WHERE S.StudId = T.StudId AND T.CrsCode = ‘CS315’)
请各位不吝赐教,⼩弟先谢过~
解:
取交集
lect a.* from
(
SELECT S.Name
FROM STUDENT S, TRANSCRIPT T
WHERE S.StudId = T.StudId AND T.CrsCode = ‘CS305’
) as a
cross join
开业礼物(
SELECT S.Name
FROM STUDENT S, TRANSCRIPT T
WHERE S.StudId = T.StudId AND T.CrsCode = ‘CS315’
) as b on a.Name = b.Name;
2.
SELECT * FROM (
SELECT DISTINCT col1 FROM t1 WHERE…溺水案例
UNION ALL
SELECT DISTINCT col1 FROM t1 WHERE…
议论文高中) AS tbl
GROUP l1 HAVING COUNT(*) = 2
3.
李强老师交集:
SELECT * FROM table1 AS a JOIN table2 AS b ON a.name =b.name
举例:
表a:
FieldA
001
002
003
表b:
FieldA
001
002
003
004
请教如何才能得出以下结果集,即表A, B⾏交集
FieldA
001
002
003
答案:lect a.FieldA from a inner join b on a.FieldA=b.FieldA
差集:
NOT IN 表⽰差集
SELECT * FROM table1 WHERE name NOT IN (SELECT name FROM