多个表的多个总和

时间:2017-03-27 15:08:26

标签: php mysql

我一直试图将每个表格中的总数加在一起。我使用过在线查询生成器,但我认为不对。

"SELECT SUM(total) mailTotal,
         SUM(total) extraTotal,
         SUM(total) fbaTotal, 
         SUM(total) gdnTotal,
         SUM(total) ppcTotal,
         SUM(total) smTotal, 
         SUM(total) webTotal
FROM admail,
     extra_charges,
     facebook_adds,
     gdn,
     ppc,
     social_media,
     web
WHERE client = 1"

1 个答案:

答案 0 :(得分:0)

您应该尝试以下方式:

SELECT SUM(ad.total)  as mailTotal,
       SUM(ex.total)  as extraTotal,
       SUM(fa.total)  as fbaTotal,
       SUM(gdn.total) as gdnTotal,
       SUM(ppc.total) as ppcTotal,
       SUM(sm.total)  as smTotal,
       SUM(w.total)   as webTotal
FROM   admail ad,
       extra_charges ex,
       facebook_adds fa,
       gdn gdn,
       ppc ppc,
       social_media sm,
       web w
WHERE  ad.client = 1 

当然这对你有用:)