I have two tables. It is much more complex data than the example but I am trying to simplify it.
LUNCH - DINNER with the same columns.
LUNCH Table:
Date | LogTime | Who | Color | Food | Started | Finished
2014-01-01 | 09:00:00 | Bill | Red | Beets | 09:01:00 | 10:00:00
2014-01-01 | 09:15:00 | Tom | Red | Tomatos | 09:16:00 | 09:45:00
2014-02-02 | 10:00:00 | Bill | Blue | Beets | 10:15:00 | 10:45:00
DINNER Table:
Date | LogTime | Who | Color | Food | Started | Finished
2014-01-01 | 22:00:00 | Bill | Red | Chicken | 22:01:00 | 23:00:00
2014-01-01 | 21:15:00 | Tom | Red | Turkey | 21:16:00 | 21:45:00
2014-02-03 | 13:00:00 | Bill | Red | Stew | 14:15:00 |14:45:00
I am trying to output data grouped by WHO column. Example of what I am trying to achieve.
WHO | Total | Total_red | Total_Blue | Total_Beets | Total_Tomatos | Total_Turkey
Bill 4 3 1 2 0 0
Total_Chicken | Last_Lunch_Date| Last_Lunch_Color | Last_Dinner_Date | Last_Dinner_Color
1 2014-02-02 Blue 2014-02-03 Red
Can this be done in a single query?
Actual Table is about 600 Million rows
Sign up
Already have an account? Login
Welcome to the Rocket Forum!
Please log in or register:
Employee Login | Registration Member Login | RegistrationEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.
. Change the view to add an extra column: