Welcome Guest, Not a member yet? Register   Sign In
Need help with data arrays
#8

Ah, I think I understand now. You want one row per staff member and the total for each absence type on the same row, like this?
Code:
id  name     absent  sick
01  Michael     1      2
02  Jennifer    3      0
03  Thomas      0      0
04  Carlos      0      1
05  Mary        2      1

Quote:blackbulldog:
Also, if there are no records of the specified type in the date range for any staff member the the totals return as NULL ... is there a way to get the query to return 0 rather than NULL?

I'm getting out of my depth here (my SQL isn't that good), LOL, but there's a function called COALESCE() that should do the trick. The COALESCE() function returns the first non-NULL value from a list of values. I think you'll have to use it on both fields.
Code:
instead of
SELECT events.staffid, SUM(amount) AS total_absence

try this
SELECT COALESCE(events.staffid, 0),
       COALESCE(SUM(amount) AS total_absence, 0)
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply


Messages In This Thread
Need help with data arrays - by blackbulldog - 03-14-2015, 08:28 AM
RE: Need help with data arrays - by RobertSF - 03-14-2015, 04:01 PM
RE: Need help with data arrays - by blackbulldog - 03-15-2015, 05:04 AM
RE: Need help with data arrays - by RobertSF - 03-15-2015, 05:42 AM
RE: Need help with data arrays - by blackbulldog - 03-16-2015, 04:46 AM
RE: Need help with data arrays - by RobertSF - 03-16-2015, 12:34 PM
RE: Need help with data arrays - by blackbulldog - 03-16-2015, 01:27 PM
RE: Need help with data arrays - by RobertSF - 03-16-2015, 05:36 PM
RE: Need help with data arrays - by RobertSF - 03-16-2015, 03:24 PM
RE: Need help with data arrays - by blackbulldog - 03-17-2015, 01:57 AM
RE: Need help with data arrays - by RobertSF - 03-17-2015, 03:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB