Reputation: 497
Was wondering if there's a better way to run this query, since BETWEEN repeats it self, I only need to add a new rule (and local=1)
OUTPUT is what I want, just wondering if there's a shorter or better version.
SCHEMA & RESULT: http://sqlfiddle.com/#!9/e147c/2
SELECT COUNT(*) as total,
(SELECT COUNT(*) FROM orden WHERE actual_date BETWEEN '2017-01-01' AND '2017-01-05' and local=1 and forma_pago='tarjeta' and status=4) as Principal
FROM orden
WHERE actual_date BETWEEN '2017-01-01' AND '2017-01-05'
and forma_pago='tarjeta'
and status=4
Upvotes: 1
Views: 43
Reputation: 3810
This should do it:
SELECT COUNT(*) AS total
, SUM(CASE
WHEN local = 1 THEN 1
ELSE 0
END) AS Principal
FROM orden
WHERE actual_date BETWEEN '2017-01-01' AND '2017-01-05'
AND forma_pago = 'tarjeta'
AND status = 4;
sql Fiddle:
http://sqlfiddle.com/#!9/e147c/3
Upvotes: 2