How can I do boolean logic on two columns in MySQL?

前端 未结 7 904
野的像风
野的像风 2021-01-18 06:41

I want to do a select in MySql that combines several columns... something like this pseudocode:

SELECT payment1_paid AND payment2_paid AS paid_in_full 
FROM          


        
7条回答
  •  独厮守ぢ
    2021-01-18 07:08

    If by combine you mean concatenate then this will work:

    select concat(payment1_paid, payment2_paid) as paid_in_full
    from denormalized_payments where payment1_type = 'check';
    

    If by combine you mean add, then this should work:

    select payment1_paid + payment2_paid as paid_in_full
    from denormalized_payments where payment1_type = 'check';
    

    [EDIT]

    For boolean AND:

    select payment1_paid && payment2_paid as paid_in_full
    from denormalized_payments where payment1_type = 'check';
    

提交回复
热议问题