给定伪表:
+-----+---------------------+------+
| tag | data | read |
+-----+---------------------+------+
| A | 2013-10-10 15:00:00 | 1345 |
+-----+---------------------+------+
| A | 2013-10-10 15:15:00 | 3454 |
+-----+---------------------+------+
| A | 2013-10-10 15:30:00 | 2345 |
+-----+---------------------+------+
| A | 2013-10-10 15:45:00 | 1132 |
+-----+---------------------+------+
| B | 2013-10-10 15:00:00 | 6234 |
+-----+---------------------+------+
| B | 2013-10-10 15:15:00 | 5432 |
+-----+---------------------+------+
| B | 2013-10-10 15:30:00 | 4563 |
+-----+---------------------+------+
| B | 2013-10-10 15:45:00 | 5432 |
+-----+---------------------+------+是否可以仅使用SQL应用下列公式?
示例:
result=AVG(A)-(AVG(B)+AVG(C))或
result=AVG(A)+AVG(B)按日期分组?
发布于 2013-10-22 16:58:50
它应该计算结果
以下是SqlFiddle上的演示。
select (AVG(case when tag = 'A' then read end) + AVG(case when tag = 'B' then read end)) 'result', data
from TBL
group by data发布于 2013-10-22 17:33:52
您可以为每个标记分别选择sum或avg,然后在每个查询上使用您想要的操作进行选择。
select (select SUM([read]) from table where tag = 'A') +
(select SUM([read]) from table where tag = 'B') https://stackoverflow.com/questions/19523688
复制相似问题