Query Help - Merging Queries
Date: 12/28/05
(MySQL Communtiy) Keywords: no keywords
I want to merge these three queries into one query (and then add more) but I cant seem to wrap my head arround combining the first two.
ultimately I want to combine the 3 subtotals into one value.
Query1
SELECT invoice_number, sum(((TIME_TO_SEC(end_time) - TIME_TO_SEC(start_time))/3600) * rate) AS subtotal
FROM invoice_items
WHERE office_id='$office_id' AND service_type!='225'
GROUP BY invoice_number
ORDER BY invoice_number
Query2
SELECT invoice_number, sum((1) * rate) AS subtotal
FROM invoice_items
WHERE office_id='$office_id' AND service_type='225'
GROUP BY invoice_number
ORDER BY invoice_number
Query3
SELECT invoice_number, sum((mileage*mileage_rate)+groceries_value-discount_value) AS subtotal
FROM invoice_main
WHERE office_id='$office_id'
GROUP BY invoice_number
ORDER BY invoice_number
Source: http://www.livejournal.com/community/mysql/79721.html