Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用mysql显示特定项目在特定日期花费的总金额_Mysql - Fatal编程技术网

如何使用mysql显示特定项目在特定日期花费的总金额

如何使用mysql显示特定项目在特定日期花费的总金额,mysql,Mysql,以下是我的表格数据: date | item price | +----+------------+-------------+----+ 2021-02-14 | Miscellaneous | 320 | 2021-02-14 | Miscellaneous | 1000 | 2021-02-14 | Labour | 500 | 2021-02-14 | Excavation | 3400 | 2021-0

以下是我的表格数据:

  date       | item           price | 
+----+------------+-------------+----+
 2021-02-14 | Miscellaneous |   320 | 
 2021-02-14 | Miscellaneous |  1000 | 
 2021-02-14 | Labour        |   500 |
 2021-02-14 | Excavation    |  3400 |
 2021-02-14 | Cement        |   160 |
 2021-02-14 | Miscellaneous |   320 |
 2021-02-14 | Miscellaneous |   600 |
 2021-02-15 | Miscellaneous |   320 | 
 2021-02-15 | Miscellaneous |  1000 | 
 2021-02-15 | Labour        |   500 |
 2021-02-16 | Excavation    |  3400 |
 2021-02-16 | Cement        |   160 |
 2021-02-16 | Miscellaneous |   320 |
 2021-02-17 | Miscellaneous |   600 |
我运行的查询在特定日期运行良好

select item, date, sum(price) as total 
from transactions 
WHERE date = '2021-02-14' 
GROUP BY item
输出结果如下所示

+---------------+------------+-------+
| item          | date       | total |
+---------------+------------+-------+
| Cement        | 2021-02-14 |   160 |
| Excavation    | 2021-02-14 |  3400 |
| Labour        | 2021-02-14 |   500 |
| Miscellaneous | 2021-02-14 |  2240 |
+---------------+------------+-------+
现在我需要一个查询,该查询将给出其他日期的以下输出,预期输出如下:

+---------------+------------+-------+
| item          | date       | total |
+---------------+------------+-------+
| Cement        | 2021-02-14 |   160 |
| Excavation    | 2021-02-14 |  3400 |
| Labour        | 2021-02-14 |   500 |
| Miscellaneous | 2021-02-14 |  2240 |
| Labour        | 2021-02-15 |   500 |
| Miscellaneous | 2021-02-15 |  1320 |
| Cement        | 2021-02-16 |   160 |
| Excavation    | 2021-02-16 |  3400 |
| Miscellaneous | 2021-02-16 |   320 |
| Miscellaneous | 2021-02-17 |   600 |
+---------------+------------+-------+

欢迎提供任何帮助。

此查询将解决您的问题

select item, date, sum(price) as total from transactions GROUP BY item, date ORDER by date;

按项目、日期分组
有什么问题吗?谢谢你。。。我知道我错过了一些东西,非常接近查询。。。