When I want to use Where
clause to total_debtor_price
and total_debtor_price
I got this error message:
Unable to resolve column
total_debtor_price
(ortotal_creditor_price
);
my query works fine without where
clause.
DROP TEMPORARY TABLE IF EXISTS tmp_AccountingDocument_datatable;
CREATE TEMPORARY TABLE tmp_AccountingDocument_datatable
SELECT
TAD.*,
(
SELECT SUM(TADD.debtor_price) AS total_debtor_price
FROM Vw_AccountingDocumentDetail TADD
WHERE TADD.accounting_document_id = TAD.id
) total_debtor_price,
(
SELECT SUM(TADD.creditor_price) AS total_creditor_price
FROM Vw_AccountingDocumentDetail TADD
WHERE TADD.accounting_document_id = TAD.id
) total_creditor_price
FROM Tb_Accounting_Documents TAD
WHERE IF(
NOT ISNULL(_Filter_Price_Status),
CASE
WHEN _Filter_Price_Status = 'smaller'
THEN (
total_debtor_price <= _Filter_Price OR
total_creditor_price <= _Filter_Price
)
WHEN _Filter_Price_Status = 'equal'
THEN (
total_debtor_price = _Filter_Price OR
total_creditor_price = _Filter_Price
)
WHEN _Filter_Price_Status = 'bigger'
THEN (
total_debtor_price >= _Filter_Price OR
total_creditor_price >= _Filter_Price
)
END,
TRUE
)