bitscn.com
不错的mysql联表多表查询
mysql联表多表查询,以前查询的时候,可以直接select * from tablea as a ,tableb.as b where a.cc=b.cc.今天分享一个新奇的写法,而且对于百w数据执行效率可是相当的快,下面分享一下联表多表查询的几个语句:
sql代码
#在tbl_user中删除非法积分数据的qq的邀请好友qq资料
delete from tbl_user where fqq in
(select fdesqq from tbl_invitehistory where fsrcqq in
(select distinct(fsrcqq) from tbl_scoredetail where fscore>'250' and fstrategy='4'))
#在tbl_user中删除非法积分数据的qq资料
delete from tbl_user where fqq in
(select distinct(fsrcqq) from tbl_scoredetail where fscore>'250' and fstrategy='4')
#在tbl_invitehistory中删除所有非法积分数据的邀请记录
delete from tbl_invitehistory where fsrcqq in
(select distinct(fsrcqq) from tbl_scoredetail where fscore>'250' and fstrategy='4')
#在tbl_score中删除非法积分数据的总积分
delete from tbl_score where fqq in
(select distinct(fsrcqq) from tbl_scoredetail where fscore>'250' and fstrategy='4')
#在tbl_scoredetail中删除非法积分明细
delete from tbl_scoredetail where fscore>'250' and fstrategy='4'
#删除tbl_score表里没有tbl_user的用户
delete from tbl_score where fqq not in (select fqq from tbl_user)
delete from tbl_scoredetail where fsrcqq not in (select fqq from tbl_user)
//查兑换码大于20的用户明细表
select fqq,fcode,fapplytime from tbl_code where fqq in (select a.fqq from (select count(*) as num,fqq from `tbl_code` group by fqq having num>20) as a) and fstatus='1'
bitscn.com