首页 > 数据库技术 > 详细

python学习笔记(71) SQL语句数据行操作补充

时间:2018-11-30 12:26:24      阅读:177      评论:0      收藏:0      [点我收藏+]

  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语句数据行操作补充

原文:https://www.cnblogs.com/farion/p/10043213.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!