Click to See Complete Forum and Search --> : 2 Sums, 2 Columns, 1 query


jdickson
10-08-2008, 01:20 PM
Here's my scenario. I have 2 tables, "Requested' and "Available"

Both have the fields
id
date1
hour_requested


There are multiple dates submitted in each table. I'm needing to show the sum for hour_requested for both "Requested" and "Available" listed down the page by date. Show should show as:

Date1...... Requested (Sum for date).........Available(sum for date)



Make sense? Thanks in advance, I am stumped!

chazzy
10-08-2008, 07:18 PM
you'd just use a subselect


select
r.date1,
(select count(*) from requested u where u.date1=r.date1) as requested_count,
(select count(*) from available a where a.date1=r.date1) as available_count
from requested r;

jdickson
10-09-2008, 09:42 AM
Chazzy. Many thanks for your help, that is exactly what I needed. Thank you very much! :)