求 这个语句的 其它写法

好帅的一条鱼 2012-11-07 10:52:13
这个语句是书上看的,想转换为其他写法,求,希望大侠们能有多少种,表达多少种,谢谢!
测试环境已弄好,谢谢!
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))
...全文
97 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
快溜 2012-11-07
  • 打赏
  • 举报
回复
select c1 from t1 group by c1 having (select max(x) from t2)>max(c2)
發糞塗牆 2012-11-07
  • 打赏
  • 举报
回复
有建表插数脚本,处理起来就是快。个人能力有限,就只会一种,等楼下补充
--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 行受影响)
 
 
 */

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧