Case statement in MySQL

前端 未结 6 1080
旧时难觅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:21

    MySQL also has IF():

    SELECT 
      id, action_heading, 
          IF(action_type='Income',action_amount,0) income, 
          IF(action_type='Expense', action_amount, 0) expense
    FROM tbl_transaction
    

提交回复
热议问题