1

我对此需要的查询感到震惊..

   DATE        UPSRC         UPDST         DNSRC          DNDST

   2013-07-04  1.021        1.541          0.017          23.65
   2013-07-04  1.561        9.55           4.27           5.65
   2013-07-04  41.0451      7.641          9.67           2.65
   2013-07-03  7.51         3.541          3.47           2.65
   2013-07-03  1.021        1.541          2.67           23.65
   2013-07-03  1.561        9.55           34.47          5.65
   2013-07-02  61.0451      4.641          9.57           7.09
   2013-07-02  7.51         4.541          6.67           9.65
   2013-07-02  1.021        6.541          2.543          23.345
   2013-07-01  1.561        2.55           4.367          1.65
   2013-07-01  43.0451      3.641          9.67           7.65
   2013-07-01  7.51         1.541          6.627          9.65

这是使用此查询生成的

SELECT *
FROM flows_monthly_summary
        WHERE DATE >= '2013-07-01' 
        AND DATE<='2013-07-04' 
        ORDER BY DATE DESC

现在,我想将 (UPSRC+UPDST) 列的 TOTAL 作为 UPSTREAM,将 (DNSRC+DNDST) 作为 DOWNSTREAM 按日期,如下所示:

DATE                      UPSTREAM                            DOWNSTREAM
2013-07-04       [TOTAL OF UPSRC+UPDST COLUMNS]    [TOTAL OF DNSRC+DNDST COLUMNS]
2013-07-03       [TOTAL OF UPSRC+UPDST COLUMNS]    [TOTAL OF DNSRC+DNDST COLUMNS]
2013-07-02       [TOTAL OF UPSRC+UPDST COLUMNS]    [TOTAL OF DNSRC+DNDST COLUMNS]
2013-07-01       [TOTAL OF UPSRC+UPDST COLUMNS]    [TOTAL OF DNSRC+DNDST COLUMNS]

我需要什么查询?谢谢!

4

2 回答 2

4
SELECT `Date`,Sum(UPSRC+UPDST) as  UPSTREAM ,Sum(DNSRC+DNDST) as DOWNSTREAM
FROM flows_monthly_summary
        WHERE DATE >= '2013-07-01' 
        AND DATE<='2013-07-04' 
group by [Date]
        ORDER BY DATE DESC

建议您不要使用 Date 之类的关键字作为您的coloumn name it bad habbit

于 2013-07-29T05:36:03.913 回答
0
SELECT DATE,
       SUM(UPSRC  +  UPDST) as UpStream,
       SUM(DNSRC  +  DNDST) as Downstream
FROM flows_monthly_summary
WHERE DATE >= '2013-07-01' 
        AND DATE<='2013-07-04'
GROUP BY DATE 
ORDER BY DATE DESC
于 2013-07-29T05:39:39.557 回答