Niranga Jayakody
Niranga Jayakody

Reputation: 78

mysql select condition with 3 conditions

I have table that have a field called cheque_type and this filed comes with 3 variables such as Life,NonMotor,Motor

And the table has a time stamp. I need to get a result that how many Life, Nonmotor , Motors checks are printed

What i need is add another 3 columns to this sql query and get the number of results according to the category

SELECT DATE(`timestamp`) As ___Date___,
COUNT(`id`) as Total,
SUM(print_status) as Printed,
(COUNT(`id`) - SUM(print_status)) as to_be_print
FROM cheque.vouchers
WHERE
DATE( `timestamp`)  >='2014-11-15'
AND DATE( `timestamp`)  <='2014-11-31'
group by DATE(`timestamp`) ;

enter image description here

Upvotes: 0

Views: 316

Answers (1)

juergen d
juergen d

Reputation: 204924

SELECT DATE(`timestamp`) As ___Date___,
       COUNT(`id`) as Total,
       SUM(print_status) as Printed,
       (COUNT(`id`) - SUM(print_status)) as to_be_print,
       sum(cheque_type = 'Life') as life_check,
       sum(cheque_type = 'NonMotor') as non_check,
       sum(cheque_type = 'Motor') as motor_check
FROM cheque.vouchers
WHERE DATE( `timestamp`)  >='2014-11-15'
AND DATE( `timestamp`)  <='2014-11-31'
group by DATE(`timestamp`) ;

Upvotes: 1

Related Questions