http://qiutian110119.blog.163.com/blog/static/54617311201131015915294/
1.insert
批量添加
insert into xxx values (), (), ()
2.update
级联更新
update A, B set A.a = a1, B.b = b1 where A.id = B.aid
3.delete
级联删除
delete A, B from A, B where A.id = B.aid
4.limit
select * from x
limit 2
返回第2条结果
or limit 2, 10
返回第2条到第12条结果
5.group by
select A.name, sum(A.num), A.price
from A
group by A.name
其他的数据库对此sql语句会报错,而mysql则不会。
A.price从组中任选一个。
6.rand()
select * from A order by rand()
随机排序
7.replace
replace into x values(...)
或者
replace into x select * from y
本文介绍了SQL的基本操作,包括批量插入数据、级联更新与删除、使用LIMIT限制查询结果数量、GROUP BY进行数据分组汇总、RAND()实现随机排序以及REPLACE进行数据替换等常用技巧。

1678

被折叠的 条评论
为什么被折叠?



