首页 > 其他 > 详细

子查询

时间:2018-12-17 01:03:49      阅读:194      评论:0      收藏:0      [点我收藏+]

子查询在()中写sql语句

 

 技术分享图片

 

1.单列子查询

查询一列中的一个值。

  select  * from  table  

where  列1 = (select  列1 from  table  where  列3 = 值)

and 列2=(select  列2  from  table where  列3 = 值 

 


2.单行子查询

查询出多列

  

select  t1.列1,t2.列2,t3.列3  from  table1  t1, (select 列2 from table t2 group by 列2) ,table3  t3

 

where   t1.列5=t2.列5 and t2.列4=t3.列6;

 

 

3.多行子查询

查询多条记录数据

 

in   主查询语句结果在子查询语句

  select * from table  where  列1 in (select max(列1)  from table  group by 列2 );

any

  select * from table  where  列1 = any (select max(列1)  from table  group by 列2 );

all  主查询语句的结果大于或小于子查询语句的结果

select * from table  where  列1 = any (select max(列1)  from table  group by 列2 );

 

 

  

 

子查询

原文:https://www.cnblogs.com/topzhangRX/p/10111655.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!