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;

     

  • 相关阅读:
    在字符串中查找指定字符(15)
    说反话 (20)
    鼠标经过显示问题
    Java数据库连接池-proxool
    mysql中MAX()函数和count()函数的技巧使用
    Java中多线程问题
    eclipse开发文档模板
    方法调用中的别名问题
    php类的定义
    通知浏览器下载文件,而不是直接打开下载
  • 原文地址:https://www.cnblogs.com/zhengleilei/p/9128652.html
Copyright © 2011-2022 走看看