zoukankan      html  css  js  c++  java
  • 常用sql整理

    查所有数据

    select * from table;

    查询带条件

    select * from table where 1=1;

    查询分组

    select field from table group by field;

    查询嵌套子查询

    select * from (select * from table where 1=1) as t;

    两张表联查

    select * from table1 as t1 (left/right/full outer) join table2 as t2 on t1.field1 = t2.field1

    三表及以上联查

    select * from table1 as t1,table2 as t2,table3 as t3 where t1.field1 = t2.field1 and t2.field1 = t3.field1

    分页查询

    select * from testtable limit 20 offset 0;     // 从第0开始,查20条
    select * from testtable limit 20 offset 40;    // 从第40开始,查20条

    模糊查询

    select * from table where field like '%val1%'

    查超过一天前的数据

    select * from table where date(now()) - FROM_UNIXTIME(time_field, '%Y%m%d') > 0;

    添加(字符串需加" ")

    insert into table(field1,field2) values(val1,val2);

    修改所有数据

    update table set field1=val1,field2=val2;

    修改一条数据(字符串需加" ")

    update table set field1=val1,field2=val2 where field=val3;

    批量修改数据(字符串需加" ")

    update table set field1=val1 where field2 in (val2,val3,val4)

    删除所有数据

    delete from table

    删除一条数据(字符串需加" ")

    delete from table where field=val1
  • 相关阅读:
    hdu 4614 线段树 二分
    cf 1066d 思维 二分
    lca 最大生成树 逆向思维 2018 徐州赛区网络预赛j
    rmq学习
    hdu 5692 dfs序 线段树
    dfs序介绍
    poj 3321 dfs序 树状数组 前向星
    cf 1060d 思维贪心
    【PAT甲级】1126 Eulerian Path (25分)
    【PAT甲级】1125 Chain the Ropes (25分)
  • 原文地址:https://www.cnblogs.com/zyfeng/p/13689473.html
Copyright © 2011-2022 走看看