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

    1、最简单查询:

    select * from car;

    2、查询制定列:

    select name oil,powers from car;

    3、对查出的列名修改名字:

    select name as '车名',oil as '油耗',powers as '动力' from car;

    4、按条件查询:

    select name,oil,powers from car where oil = 8.7;

    5、多条件查询:

    select name,oil,powers from car where oil = 8.7 or powers = 160;
    select name,oil,powers from car where oil = 8.7 and powers = 160;

    6、范围查询:

    select * from car where price>=40 and price <=60;
    select * from car where price between 40 and 60;

    7、离散查询:

    select * from car where powers = 130 or powers = 150 or powers = 170;
    select * from car where powers in (130,150,170);
    select * from car where powers not in (130,150,170);

    8、模糊查询:

    select * from car where name like '%宝马%';
    select * from car where name like '_宝马%';

    9、排序查询:  asc 升序 desc 降序    order by

    select * from car order by oil asc;
    select * from car order by brand asc,price desc;

    10、去重复查询:  distinct

    select distinct brand from car;

    11、分页查询:

    select * from car limit 5,5;
    n;m = 5;
    limit (n-1)*m,m;   【补充】

    12、聚合函数查询:

    count(列名) sum(列名) avg(列名) max(列名) min()
    select count(*) from car;
    select sum(price) from car;
    select avg(price) from car;
    select max(price) from car;
    select min(price) from car;

     

  • 相关阅读:
    Google Chrome 自定义协议(PROTOCOL)问题的处理
    C# 6.0/7.0 的新特性
    MySQL 5.7.18 压缩包版配置记录
    nginx.conf文件内容详解
    博客添加动态动漫妹子
    TypeScript 3.8beta版
    微信浏览器H5开发常见的坑
    Babel7知识梳理
    雅虎前端优化35条规则
    webpack
  • 原文地址:https://www.cnblogs.com/zhengleilei/p/9128652.html
Copyright © 2011-2022 走看看