我的桌子t如下:
+------+----------+-------------+-----------+
| Acct | Date | Totalamount | Totalcost |
+------+----------+-------------+-----------+
| 1 | 1/1/2013 | 10 | 4 |
| 2 | 1/1/2013 | 20 | 4 |
| 3 | 1/2/2013 | 30 | 4 |
| 4 | 1/2/2013 | 40 | 4 |
| 5 | 1/3/2013 | 50 | 4 |
| 6 | 1/4/2013 | 60 | 4 |
| 7 | 1/6/2013 | 70 | 4 |
| 8 | 1/7/2013 | 10 | 4 |
+------+----------+-------------+-----------+
我想在sql中获得如下结果
+-------------------------------------------+------------------+-----------------------------+-----------------------------+
| sum(totalamount)/count(distinct(date)) | sum(Totalamount) | sum(count(distinct(date)) | sum(count(distinct(acct)) |
+-------------------------------------------+------------------+-----------------------------+-----------------------------+
| x | x | x | x |
| x | x | x | x |
| x | x | x | x |
| x | x | x | x |
| x | x | x | x |
| x | x | x | x |
| x | x | x | x |
+-------------------------------------------+------------------+-----------------------------+-----------------------------+
尝试使用 从...中选择 分组
答案 0 :(得分:0)
这将导致单行结果:
SELECT
sum(totalamount)/count(distinct date)
, sum(Totalamount)
, count(distinct date)
, count(distinct acct)
FROM yourtable
该样本数据将导致: 48.33333333、290、6、8
似乎没有要分组的东西,这会导致多个结果行。