View difference between Paste ID: mR902XFi and KVwiP4iR
SHOW: | | - or go back to the newest paste.
1
select 
2
    id,
3
    issue,
4
    delivery,
5
    proforma,
6
    restoration,
7
    deleted,
8
    IFNULL(delivery, issue) as date,
9
    totalPrice totalPrice,
10
    ROUND(totalPrice * (1 - discount / 100), 2) as discountPrice,
11-
    (SELECT 
11+
    (
12-
            sum(price) sum
12+
	SELECT SUM(payment.price) sum FROM payment
13-
        FROM
13+
	WHERE payment.invoice_id = invoice.id
14-
            payment
14+
    ) payment_sum
15-
        WHERE
15+
FROM invoice
16-
            invoice_id = id
16+
WHERE invoice.deleted = 0 and invoice.user_id = 25
17-
        GROUP BY invoice_id)
17+
HAVING invoice.date BETWEEN '2014-05-01' AND '2014-05-31'
18-
from
18+
ORDER BY invoice.issue DESC