gpt4 book ai didi

php - 如何 "SUM"唯一列值并按日期过滤

转载 作者:太空宇宙 更新时间:2023-11-03 11:56:13 25 4
gpt4 key购买 nike

<分区>

输入

+------------+----------+-----------+-------+-------------+
| cardNo | userName | tablename | hours | date |
+------------+----------+-----------+-------+-------------+
| 1 | a | a | 12 | 12-06-2015 |
| 1 | a | a | 5 | 11-06-2015 |
| 2 | b | b | 3 | 15-06-2015 |
| 1 | a | a | 8 | 12-06-2015 |
| 2 | b | b | 3 | 21-06-2015 |
| 1 | a | a | 12 | 14-06-2015 |
| 2 | b | b | 10 | 8-06-2015 |
+------------+----------+-----------+-------+-------------+

cardNo 是唯一的。我需要显示每张卡片的所有详细信息和总小时数,例如:

期望的输出

+--------+----------+-----------+-------------+
| cardNo | userName | tablename | totalhours |
+--------+----------+-----------+-------------+
| 1 | a | a | 37 |
| 2 | b | b | 16 |
+--------+----------+-----------+-------------+

我的查询

SELECT cardNo,sum(hours) 
FROM yourtable
GROUP BY cardNo;

但我需要 totalHours >=20 是 'N'。

SELECT cardNo,sum(hours) 
FROM yourtable where totalHours>=20
GROUP BY cardNo;

我无法得到正确答案。如果我指定 totalHours>=1 它会给出正确答案;我能做些什么?而且我还需要用于该查询的 PHP 获取代码。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com