1、行读锁
select * from table where id =1 for update (悲观锁)
update table set status=1 where status = 0 and order_id = xxx;(乐观锁)
2、千万级行数据分页优化读取
select * from table where id>=(select id from table order by id limit 90000,1) limit 10;
3、in
select * from table where in(1,2,3,4);
4、行数据对比(数学成绩与语文成绩对比)
https://www.aliyun.com/jiaocheng/1107496.html
SELECT s.sid,s.sname,s.sage,s.ssex,sc1.score,sc2.score FROM student s,sc sc1,sc sc2 WHERE sc1.cid = 1 AND sc2.cid = 2 AND sc1.score > sc2.score AND sc1.sid = sc2.sid AND s.sid = sc1.sid;
5、在一条SQL中同时查出2006和2007年的数量
select COUNT(release_year=2006 OR NULL) AS ‘2006年电影数量’,COUNT(release_year=2007 OR NULL) AS ‘2006年电影数量’ from table …..
mysql 经典SQL语句
最新推荐文章于 2024-09-07 15:53:50 发布