关于SQL查询 柔情只为你懂 2022-05-20 03:45 165阅读 0赞 个人总结工作上常用的SQL查询语句: 单表查询 1.简单查询 select \* from table 2.查询表中某个字段 select t.xx from table t 3.条件查询 select t.xx from table t where t.id = ?; 3.根据某字段排序,降序/升序 select \* from table t where t.id = ? order by t.xx desc/asc 4.分页 select \* from table limit 0,100;//检索记录0到100行 select \* from table limit 96,-1;//检索记录96到最后行 select \* from table limit 100;//检索前100行 5.连表查询 left ,right ,inner select \* from tableA a left join tableB b on a.id = b.id 注意 [关于mybatis中collection一对多关联查询分页出错问题总结][mybatis_collection] [UNION 和 UNION ALL了解][UNION _ UNION ALL] 6. 分组查询 select \* from table a where a.id = ? group by a.xx having count(id)>2; 注意分组查询时,其他字段只显示一个的问题 [mybatis_collection]: https://blog.csdn.net/baidu_38116275/article/details/78622669 [UNION _ UNION ALL]: http://www.w3school.com.cn/sql/sql_union.asp
还没有评论,来说两句吧...