SELECT * FROM
(
SELECT
tbl_invoice.id,
SUM(tbl_invoice.pay_amount) AS pay_amount,
tbl_invoice.create_at,
tbl_invoice.sale_id,
tbl_invoice.cus_id,
tbl_sale_detail.name AS project_name,
MIN(tbl_invoice.date_to_pay) AS date_to_pay,
CONCAT(
tbl_customers.first_name,
" ",
tbl_customers.last_name
) AS customer_name,
COUNT(tbl_invoice.status) AS status_count,
COUNT(
CASE
WHEN tbl_invoice.status= 0 THEN
1
ELSE
NULL
END
) AS status_paid,
tbl_invoice.status
FROM
tbl_sale
JOIN tbl_sale_detail ON tbl_sale_detail.sale_id = tbl_sale.id
JOIN tbl_invoice ON tbl_invoice.sale_id = tbl_sale.id
JOIN tbl_customers ON tbl_customers.id = tbl_invoice.cus_id
GROUP BY
tbl_invoice.sale_id
ORDER BY
tbl_invoice.id DESC
) AS invoice_completed
WHERE status_paid = 0
17 January, 2018
Using CASE WHEN & SELECT in SELECT * FROM
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment