1. CURD操作

  1. -- 增加数据
  2. insert staffs(name,gender,salary,email,birthday) values
  3. ('test','male',99999,'test@php.cn','2021-1-1');
  4. -- 删除数据
  5. delete from staffs where salary = 99999;
  6. -- 修改数据
  7. update staffs set salary = salary + 1000 where salary < 5000;
  8. -- 条件查询
  9. select sid,name,salary from staffs where salary>9000;
  10. -- 条件查询,并按年龄从大到小排序
  11. select sid,name,birthday,salary from staffs where salary>9000
  12. order by timestampdiff(year, birthday, now()) desc;
  13. -- 模糊条件查询
  14. select sid,name from staffs where name like 'a%';
  15. select sid,name from staffs where name like '__m%';
  16. -- 分组查询
  17. select gender, count(*) num from staffs group by gender;
  18. -- 关联查询
  19. select aid,title,name from articles a, categories c where a.cid = c.cid;
  20. -- 所有国内新闻,改为c.cid=2, 为查所有国外新闻
  21. select aid,title,name from articles a, categories c where a.cid = c.cid and c.cid=1;
  22. -- 简化,哪果关联表中有同名字段,可以简化为如下
  23. select aid,title,name from articles natural join categories;

2. 预处理

  1. -- 生成预处理sql语句, ?号作占位符;
  2. prepare sqlStr from 'select sid,name,salary from staffs where salary > ? and salary < ? order by salary desc';
  3. -- 将真实的数据绑定到预处理语句的占位符上;
  4. set @sal1 = 6000, @sal2 = 10000;
  5. -- 执预处理sql语句
  6. execute sqlStr using @sal1, @sal2;

更多相关文章

  1. SQL Server学习之路(一)
  2. 练习CURD常用操作,select查询与关联操作,预处理原理
  3. C# 数据操作系列 - 16 SqlSugar 完结篇
  4. C# 数据操作系列 - 13 SqlSugar 初探
  5. C# 数据操作系列 - 17 Dapper ——号称可以与ADO.NET 同台飙车的
  6. MySQL的EXPLAIN其实很简单
  7. CURD常用操作、select常用查询、预处理原理
  8. MySQL基础: 预处理和常用的MySQL函数
  9. mysql CURD常用操作及预处理机制

随机推荐

  1. Android(安卓)开发四大天王 四大组件 (很
  2. Android UI之TextView实现跑马灯效果
  3. 第16天android:看android的书籍
  4. FAQ_15_android Imageview ImageButton B
  5. [Android] ExpandableListView 子目录点
  6. android shape用法
  7. Android内存管理机制
  8. Android 4.0.3 CTS 测试
  9. android系统工具之 draw9patch超详细教程
  10. Spinner的三级联动