Case statement in MySQL

前端 未结 6 1092
旧时难觅i
旧时难觅i 2020-11-29 00:54

I have a database table called \'tbl_transaction\' with the following definition:

id INT(11) Primary Key
action_type ENUM(\'Expense\', \'Inc         


        
6条回答
  •  青春惊慌失措
    2020-11-29 01:19

    Try to use IF(condition, value1, value2)

    SELECT ID, HEADING, 
    IF(action_type='Income',action_amount,0) as Income,
    IF(action_type='Expense',action_amount,0) as Expense
    

提交回复
热议问题