imperium2335 Posted March 8, 2012 Share Posted March 8, 2012 Hi, I have a query that calculates three totals in three different currencies, so there are 3 rows output each with 3 columns. $result = $dbh->query("SELECT SUM(((SELECT SUM((quantity*(sellingNet+sellingVat))) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id AND parts_trading.sellingCurrency = 1)+(SELECT SUM(feeAmountNet+feeAmountVat) FROM enquiries_custom_fees WHERE enquiries_custom_fees.enquiryRef = enquiries.id))) AS salesTotalPounds, SUM(((SELECT SUM((quantity*(sellingNet+sellingVat))) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id AND parts_trading.sellingCurrency = 2)+(SELECT SUM(feeAmountNet+feeAmountVat) FROM enquiries_custom_fees WHERE enquiries_custom_fees.enquiryRef = enquiries.id))) AS salesTotalDollars, SUM(((SELECT SUM((quantity*(sellingNet+sellingVat))) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id AND parts_trading.sellingCurrency = 3)+(SELECT SUM(feeAmountNet+feeAmountVat) FROM enquiries_custom_fees WHERE enquiries_custom_fees.enquiryRef = enquiries.id))) AS salesTotalEuros, (SELECT SUM(jobs_payments.amount) FROM jobs_payments WHERE currencyRef = 1 AND jobRef = jobs.id) AS paidAmountPounds, SUM(((SELECT SUM((quantity*(sellingNet+sellingVat))) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id)+(SELECT SUM(feeAmountNet+feeAmountVat) FROM enquiries_custom_fees WHERE enquiries_custom_fees.enquiryRef = enquiries.id)-jobs_payments.amount)) AS balanceTotal FROM jobs LEFT JOIN jobs_payments ON jobs.id = jobs_payments.jobRef, enquiries, users, branches, entity_details, (SELECT currencyRef, SUM(amount) AS total FROM jobs_payments GROUP BY currencyRef) AS paidTotalsTable WHERE enquiries.traderRef = users.id AND jobs.enquiryRef = enquiries.id AND users.branchRef = branches.id AND enquiries.entityRef = entity_details.id AND entity_details.paymentTermsRef = 1 AND (SELECT SUM(quantity*(sellingNet+sellingVat)) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id) != '' AND ((SELECT SUM((quantity*(sellingNet+sellingVat))) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id)+(SELECT SUM(feeAmountNet+feeAmountVat) FROM enquiries_custom_fees WHERE enquiries_custom_fees.enquiryRef = enquiries.id)) != jobs_payments.amount AND ((SELECT SUM((quantity*(sellingNet+sellingVat))) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id)+(SELECT SUM(feeAmountNet+feeAmountVat) FROM enquiries_custom_fees WHERE enquiries_custom_fees.enquiryRef = enquiries.id)-jobs_payments.amount) > 0 AND jobs.stateRef != 5") ; The problem is, is that 'paidAmountPounds' only shows the value of the first row in that quiery (£40, but should by much much more). Does any one know how I can fix this? Quote Link to comment https://forums.phpfreaks.com/topic/258516-mysql-query-help/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.