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
  • 相关阅读:
    Android开发之Sqlite的使用
    ZOJ 3607 Lazier Salesgirl
    ZOJ 3769 Diablo III
    ZOJ 2856 Happy Life
    Ural 1119 Metro
    Ural 1146 Maximum Sum
    HDU 1003 Max Sum
    HDU 1160 FatMouse's Speed
    Ural 1073 Square Country
    Ural 1260 Nudnik Photographer
  • 原文地址:https://www.cnblogs.com/zyfeng/p/13689473.html
Copyright © 2011-2022 走看看