zoukankan      html  css  js  c++  java
  • 数据库查询

    1. asc 默认排序方式(从小到大),desc 从大到小';

    2. 多表查询:

      • 连表查询

        • 连表:总是在连接的时候创建一张大表,里面存放的是两张表的笛卡尔积。
        • 再根据条件筛选就可以了
      • 子查询

        • 查询平均年龄在25岁以上的部门名:

          • Select name from department where id in (select dep_id from employee group by dep_id having avg(age)>25);
        • 查询部门年龄大于部门平均年龄的员工姓名和年龄;

          • Select name,age from employee as t1 inner join (select dep_id,avg(age) as avg_age from employee group by dep_id) as t2 on t1.dep_id = t2.dep_id where age > avg_age;
          • 结果:pass
        • 如果一个问题既可以使用连表查询,又可以子查询,推荐使用连表查询。因为效率高。

      • 表与表之间的连接方式:

        • 内连接

          • select * from 表1,表2 where 条件;

          • select * from 表1 inner join 表2 on 条件;

          • select * from 表1 inner join 表2 on 条件 where 条件;

        • 外连接:

          • 左外连接
            • left join。。。on。。。
            • 例子:select * from table1 left join table2 on 条件
          • 右外连接
            • Right join …on....
            • 例子:select * from table1 right join table2 on 条件
          • 全外连接:full join
            • select * from table1 left join table2 on 条件 union select * from table1 right join table2 on 条件
      • 练习:

        • select t2.name from department as t1 inner join employee as t2 on t1.id = t2.dep_id where t1.name = '技术';
        • select * from department as t1 inner join employee as t2 on t1.id = t2.dep_id where t1.name = '人力资源' and t2.age>40;
        • select * from department as t1 inner join employee as t2 on t1.id = t2.dep_id where t2.age>25;
        • mysql> select * from department as t1 inner join employee as t2 on t1.id = t2.dep_id order by t2.age;
    3. pymysql的学习

  • 相关阅读:
    Spring3:AOP
    Spring2:bean的使用
    Spring1:Spring简介、环境搭建、源码下载及导入MyEclipse
    Vue.js——60分钟组件快速入门(上篇)
    vue父子组件嵌套的时候遇到
    Vue.js——60分钟快速入门
    [Vue warn]: Cannot find element: #app
    关于RabbitMQ以及RabbitMQ和Spring的整合
    spring集成多个rabbitMQ
    RabbitMQ-从基础到实战(5)— 消息的交换(下)
  • 原文地址:https://www.cnblogs.com/he-qing-qing/p/13592324.html
Copyright © 2011-2022 走看看