我在数据库中查询2个表。如果用户在同一天多次显示,我想添加hours_worked字段的值。这就是我的开始:
SELECT name, date_worked, hours worked
FROM users u
INNER JOIN records r
ON u.id = r.users_id
.......
就我而言。有关如何执行此操作的SQL语法的任何帮助都会很棒吗?
答案 0 :(得分:1)
使用SUM
SELECT name, date_worked, SUM(`hours worked`) AS totalHoursWorked
FROM users u
INNER JOIN records r
ON u.id = r.users_id
GROUP BY name, date_worked