zoukankan      html  css  js  c++  java
  • SQL常用语句大全

    1.插入数据

    insert  into  表名(列1,列2,列3)values(值1,值2,值3);

    insert  into product(name,price,pic_path) values('jack',25,'updown');

    2.更新数据

    update  表名 set 列名1=值1,列名2=值2  where 条件;

    update product set name="jack",price=35 where id=2;

    3.删除数据库

    delete from 表名[where 条件]

    delete from product where id=2;

    4.查询所有数据库内容

    select * from 表名;

    select * from product;

    5.查询部分列

    select 列1,列2 from 表名;

    select id,name from product;

    6.条件查询

    #比较 =,>,<,>=,<=,!=

    select * from 表名 where列名=值;

    select * from product where id=2;

    #and与

    select * from 表名 where 条件1 and 条件2 and 条件3;

    select * from product where id=2 and name='Nike';

    #or 或

    select * from 表名 where 条件1 or 条件2 or 条件3;

    select * from product where name='Nike' or id=2;

    #not 非

    select * from 表名 where not 条件1;

    select * from product where not name='Nike';

    #in枚举

    select * from 表名where 列名 in(值1,值2,值3);

    select * from product where  id in(2,3,4,10);

    select * from product where id not in(2,3,4);

    #like模糊查询

    select * from 表名where列名 like '%值%';

    select * from product where name like '%LI%';

    #between....and  范围查询

    select * from 表名 where 列名 between 值1 and 值2;

    select * from product where created between '2010-10-10' and '2011-10-10';

    #limit行数查询

    select * from 表名 limit  n1,n2;(n1:从第几行开始,从0开始算;n2:要显示几行)

    select * from product limit 3,4;

    7.查询排序

    select * from 表名 order by列表排序方式。

    #排序方式:asc(升序),desc(降序);

    select * from product order by created desc;

    8.聚合函数

    #count 总记录数

    select  count(列名) from student;

    select count(id) from student;

    #sum 总共

    select  sum(列名) from student;

    select sum(age) from student;

    #avg  平均值

    select avg(列名)from student;

    select avg(age) from student;

    #max  最大值

    select max(列名)from student;

    select max(age) from student;

    #min  最小值

    select  min(列名) from 表名;

    select min(age) from student;

    9.子查询

    select name from student where age<(select avg(age) from student);

    select * from product where id in(select id from order);

  • 相关阅读:
    Redis&PHP的使用安装-windows版
    【JAVA】使用Eclipse依赖生成jar包时,避免最外层同时生成资源文件的配置。
    【ActiveMQ】重写监听
    【ActiveMQ】设置自动重连
    【ActiveMQ】持久化消息队列的三种方式
    【Spring】手动获取spring容器对象时,报no qualifying bean of type is defined
    【监控】使用probe对tomcat服务进行监控
    【前端】使用weinre对手机、微信浏览器页面调试
    【前端】一句命令快速合并压缩 JS、CSS
    【前端】CSS雪碧
  • 原文地址:https://www.cnblogs.com/zhouzetian/p/7392525.html
Copyright © 2011-2022 走看看