select d.c2,sum(c.num1) sum1 from (select a.co,a.c11*a.c19 num1 from (select co,c7,c8,c11,c16,c19 from ST22014_main a where c1=(select max(c1) c1 from ST22014_main )) a join (select distinct(c2) c2 from ST22032_main where c4='15' union all select distinct(c2) c2 from ST22032_main where c4='14') b on a.c7=b.c2) c join ST1209_main d on c.co=d.co group by d.c2
表情况:
http://tu.6.cn/pic/play-tu/id/0#13931828
http://tu.6.cn/pic/play-tu/id/0#13931829请各位高人指教啊,在线等解答!!!

解决方案 »

  1.   

    描述一下你想实现的功能吧。 这样别人就不需要去分析理解你的SQL语句了。
      

  2.   

    ok,好的,就是想通过ST22032_main中c4(大量重复,数字)的字段等于ST22014_main中c7的数据中c1(时间)最大的对应c11*c19值然后通过连接ST1209_main(co主键关联前面的co,c2是分组条件)分组求和
    、、、不知道描述的清不清楚啊!!见谅!
      

  3.   

    方法就是拆成多个sql慢慢找慢的sql 
      

  4.   


    select distinct(c2) c2 from ST22032_main where c4='14'这一句感觉比较慢、、、
      

  5.   


    我也想啊,可是数据库是DBA管的,我的帐号加不了,也不好随便加的
      

  6.   

    我想问下,mysql 中嵌套查询和连接查询哪个效率会高点?or与union all呢?
      

  7.   


    嵌套查询和连接查询都是连接表啊
    or与union all 我写的这个结果也一样啊,但好像没啥差别