当前位置:网站首页>MySQL if else use case use

MySQL if else use case use

2022-07-05 13:43:00 Php_ XiaoZhi

SELECT
    b.id AS " Device owners id",
    b. NAME AS " Name of device owner ",
    CONCAT(b.tel, '\t') AS " Device owner's phone ",                -- export csv Set to normal text Id card 、 cell-phone number 、 Digital order number, etc
    CONCAT(a.cdkey, '\t') AS " equipment sn code ",                     
    IF (a.fromId = 0, " company ", c. NAME) AS " Name of transferor ",               --  If 0 Show company , Other display query names
    IF (a.fromId = 0," company ",CONCAT(c.tel, '\t')) AS " Dispatcher's telephone ",
    ( case when a.type = 1 then " purchase "
               when a.type = 2 then " exchange "
               when a.type = 3 then " Activate "
      end)    AS " operation ",                                                                    -- Multi condition judgment
    FROM_UNIXTIME(a.created_at, '%Y-%m-%d %H:%i:%s') AS " Recording time "    -- Timestamp conversion time format
FROM
    db_user_pos_record_detail AS a,
    db_user AS b,
    db_user AS c
WHERE
    cdkey = '123456'
AND b.id = a.toId
AND c.id = b.pid

原网站

版权声明
本文为[Php_ XiaoZhi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140520464256.html