henk3
November 18, 2019, 3:09am
1
Hi… I am trying to get the SUM total for a specific instructor with an id for records this past week.
So far I have this but no luck with it
SELECT * FROM instructor_time_log, SUM(time_log) AS total WHERE instructor_id = 'SF_52' AND
(date > DATE_SUB(NOW(), INTERVAL 1 WEEK));
not working
henk3:
no luck with it
What exactly does that mean? This is probably the #1 worst way to try and get help on a forum. I would suggest you read this reference .
Well lets start with the basics.
SELECT * FROM instructor_time_log, SUM(time_log) AS total
You’ve mixed up your SELECT and FROM clauses. You’re trying to SELECT the sum, FROM the instructor_time_log table.
3 Likes
henk3
November 20, 2019, 3:31pm
4
This is what worked for me.
SELECT SUM(time_log) AS total FROM instructor_time_log WHERE instructor_id = ? AND date >= (CURDATE() - INTERVAL 1 WEEK)
1 Like
I’m surprised that isn’t giving some type of “reserved word” error?
Technically, date
isnt a reserved keyword, it’s just a keyword. (at least, it isnt in MySQL, which is what I assume from the structure and functions used is what we’re talking about here. YMMV in other engines.)
Using it is still a bad idea, but it won’t cause a failure.
1 Like
system
Closed
February 20, 2020, 3:57am
7
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.