求 这个语句的 其它写法
这个语句是书上看的,想转换为其他写法,求,希望大侠们能有多少种,表达多少种,谢谢!
测试环境已弄好,谢谢!
Create table t2([X] int)
Insert t2
select '2' union all
select '2' union all
select '1' union all
select '1' union all
select '8'
Create table t1([C1] char(4),[C2] int)
Insert t1
select '001','3' union all
select '002','4' union all
select '001','8' union all
select '003','7' union all
select '002','5'
select C1 from t1 group by C1 having exists(select * from t2 where t2.X>max(t1.C2))
[最优解释]
有建表插数脚本,处理起来就是快。个人能力有限,就只会一种,等楼下补充
--Create table t2([X] int)
--Insert t2
--select '2' union all
--select '2' union all
--select '1' union all
--select '1' union all
--select '8'
--Create table t1([C1] char(4),[C2] int)
--Insert t1
--select '001','3' union all
--select '002','4' union all
--select '001','8' union all
--select '003','7' union all
--select '002','5'
SELECT C1
FROM t1
GROUP BY C1
HAVING EXISTS ( SELECT *
FROM t2
WHERE t2.X > MAX(t1.C2) )
SELECT a.c1
FROM
(SELECT c1,MAX(c2)c2
FROM t1
GROUP BY c1) a INNER JOIN t2 b ON a.c2<b.x
/*
C1
----
002
003
(2 行受影响)
c1
----
002
003
(2 行受影响)
*/
[其他解释]
select c1 from t1 group by c1
having (select max(x) from t2)>max(c2)