select c.globalUid,c.badge,temp.sumB,temp.sumP from tb_user c,(select a.uid,sum(a.badge) as sumB,IFNULL(sum(b.propertyNum),0) as sumP,sum(a.badge)-IFNULL(sum(b.propertyNum),0) as cha from tb_buyfun_log a left join buyrecord b on a.uid=b.globaluid group by a.uid having cha>500) as temp where uptime>'2009-12-01 00:00:00' and globaluid=temp.uid
谁帮忙优化下这语句,我在电脑上运行后很慢,有时半天都不出来,有时连查询工具都搞起死掉,关也关不了, 各位高手帮忙看下好不?
SQL code:
select c.globalUid,c.badge,temp.sumB,temp.sumP
from tb_user c,(
select a.uid,sum(a.badge) as sumB,
IFNULL(sum(b.propertyNum),0) as sumP,
sum(a.badge)-IFNULL(sum(b.propertyNum),0) as cha
from tb_buyfun_log a left join buyrecord b on a.uid=b.globaluid
group by a.uid
having cha>500
) as temp
where uptime>'2009-12-01 00:00:00' and globaluid=temp.uid
你这是个笛卡积啊。
贴出你的
show index from tb_user
show index from tb_buyfun_log
show index from buyrecord
以及
explain select c.globalUid,c.badge,temp.sumB,temp.sumP
from tb_user c,(
select a.uid,sum(a.badge) as sumB,
IFNULL(sum(b.propertyNum),0) as sumP,
sum(a.badge)-IFNULL(sum(b.propertyNum),0) as cha
from tb_buyfun_log a left join buyrec
我对SQL SERVER和ACCESS比较熟,所以数据库的通用基础东西可以说都掌握的差不多了,我现在想要的就是以上两数据库的独特之处的介绍和应用介绍。
另外书最好对应最新版本 oracle是11g吧 10的也行;mysql是5.1吧
谢 ......
我在清理mysql的时候,一不留神将mysql(即data里的mysql文件夹)数据库给删掉了,隔了几个小时我重启了mysql软件,mysql就自动初始化了数据库,导致从删除mysql文件夹开始到重启这段时间的数据丢失,那位高手帮想想办 ......