sql查询两张表不同的数据及sql查询语句优化总结sql查询两张表不同的数据及sql查询语句优化,
⽅法⼀(推荐)
WITH C AS(SELECT Name
FROM ConsumerCouponApply A
WHERE NOT EXISTS(SELECT1
FROM ConsumerCouponApply B
WHERE B.Name = A.Name
GROUP BY B.Name )
GROUP BY A.Name
)
SELECT COUNT(1)
FROM C
⽅法⼆
WITH C AS(SELECT A.Name
FROM ConsumerCouponApply A
GROUP BY A.Name
EXCEPT
SELECT B.Name
FROM ConsumerCouponApply B
GROUP BY B.Name
)
SELECT COUNT(1)
FROM C
⽅法三
SELECT COUNT(A.Name)
FROM ConsumerCouponApply A
LEFT JOIN ConsumerCouponApply B ON A.Name = B.Name
WHERE B.ID IS NULL
⽅法四
WITH C AS(SELECT A.Name
FROM ConsumerCouponApply A
WHERE(SELECT COUNT(1)
FROM ConsumerCouponApply B
WHERE B.Name = A.Name
GROUP BY B.Name
)IS NULL
GROUP BY A.Name
)
sql语句优化方式SELECT COUNT(1)
FROM C
依次查询响应时间:
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论