zoukankan      html  css  js  c++  java
  • 子查询

    子查询在()中写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 );

      

    不怨天,不尤人;不迁怒,不贰过. 人一能之,己百之;人十能之,己千之. 做事要细心、热情、阳光,江湖处事就是人情世故。
  • 相关阅读:
    web前段学习2017.6.15
    web前段学习2017.6.13
    web前端2017.6.10
    web前段2017.6.8
    web前段学习2016.6.6
    宏任务与微任务
    浏览器兼容性问题
    TCP 和 UDP 的区别
    React如何渲染大数据量的列表?
    移动端兼容性问题
  • 原文地址:https://www.cnblogs.com/topzhangRX/p/10111655.html
Copyright © 2011-2022 走看看