1. 程式人生 > >python學習筆記(71) SQL語句數據行操作補充

python學習筆記(71) SQL語句數據行操作補充

int ike update HERE 筆記 spa delet bsp mit

  insert into tb1(name,age) values(‘alex‘,12),(‘egg‘,18);

  insert into tb2(name,age) select name,age from tb1;

  delete from tb1 where id>2 and name=‘alex‘

  update tb2 set name=‘alex‘,age=19 where id>12 and name=‘xx‘

  select * from tb1;

  select id,name from tb1;

  select id,name from tb1 where id>12 or name=‘alex‘;

  select id,name as cname from tb1 where id>12 or name=‘alex‘;

  select name,age,11 from tb2  # 11是常量

  select * from tb1 where id in (1,2,3);

  select * from tb1 where id not in (1,2,3);

  select * from tb1 where id between 1 and 5;  # 閉區間

  select * from tb1 where id in (select nid from 表);  # 先執行括號語句

通配符:

  select * from tb1 where name like "a%";  # 後續任意字符

  select * from tb1 where name like "a_";  # 後續一個字符

分頁:

  select * from tb1 limit 10;  # 前10項

  select * from tb1 limit 0,10;  #從0項開始前10項

  select * from tb1 limit 10,10;

  select * from tb1 limit 10 offset 20;  # 從20開始前10項

排序:

  select * from tb1 order by

id asc;

  select * from tb1 order by id desc;

  取後10條數據

  select * from tb1 order by id desc limit 10;

python學習筆記(71) SQL語句數據行操作補充