如何在MySQL中添加來自不同子查詢的SUM?如何將不同子查詢中的多個SUM合併爲一個結果?
JOIN ( SELECT SUM(IF(isPurchased='0', 1, 0)) AS numQuotes, customer_id FROM product1_quote GROUP BY customer_id ) p1q ON (p1q.customer_id = c.customer_id)
JOIN ( SELECT SUM(IF(isPurchased='0', 1, 0)) AS numQuotes, customer_id FROM product2_quote GROUP BY customer_id ) p1q ON (p1q.customer_id = c.customer_id)
所以我想添加這兩個並有numQuotes是總numQuotes。但是,它比這更復雜一點,因爲不同表格的數量是動態的,所以在任何情況下都可能有任何數量的子查詢。