New answers tagged

0

Part of the secret is SELECT (...)/total, ... FROM campaigns_log JOIN ( SELECT SUM(...) AS total FROM ... ) x That is, compute the total separately and make it available in the expressions. Similarly: SELECT @total := SUM(...) FROM ... SELECT (...)/@total, ...


0

Your query plan shows two table scans on leads, which is not surprising given the search predicates with OR: FROM leads WHERE to_id = lead_id OR from_id = lead_id. It also shows a spilled sort, suggesting that the sort buffer is too small. Consider rewriting your query with joins instead of subselects, something like: SELECT COALESCE(leads_to.lead_id, ...


0

As the error says, that is limitation. However, you probably want try as follows: SELECT Q.CUSTOMER, COUNT (DISTINCT CASE WHEN O.REFDOCNUM is not null and D.REFDOCNUM is not null and D.REFDOCNUM is not null THEN S.DOCNUM END ) AS HasInvoice, COUNT (DISTINCT CASE WHEN O.REFDOCNUM is not null and D.REFDOCNUM ...


Top 50 recent answers are included