您好,我有以下选择查询,可提供 4 列的输出:
SELECT (C.customer_id) AS customer_id,
CONCAT((C.first_name),' ',(C.last_name)) Customername,
(CASE WHEN l.line_status=0 THEN '0' WHEN l.line_status ='1' THEN '1' END) STATUS,
,IF(l.`line_status` = '0', 'enabled', 'disabled') AS account_status
FROM
agingdetails ad , customer c , customers_cycletype cct , customer_contact cc , line l , customer_line_mapping clm
WHERE C.customer_id = ad.customerid
AND cct.customer_id=C.customer_id
AND cc.customer_id=C.customer_id
AND cct.cycle_type= 'A'
AND c.customer_id=24
AND ad.customerid=clm.customer_id
AND clm.line_id = l.line_id
GROUP BY l.line_id
以上查询的结果为 1 个单一客户:
customer_id Customername STATUS account_status
24 ENDTEST5 1 disabled
24 ENDTEST5 0 enabled
24 ENDTEST5 0 enabled
要求是,如果这个 customer_id 的 STATUS 列在总共 3 行中显示为状态“1”,那么它也应该在 account_status 列中为其他剩余行显示“禁用”。类似于下面的内容。
customer_id Customername STATUS account_status
24 ENDTEST5 1 disabled
24 ENDTEST5 0 disabled
24 ENDTEST5 0 disabled
TIA 给所有人。
答案 0 :(得分:1)
...
IF(SUM(l.`line_status`) OVER (PARTITION BY C.customer_id, C.first_name, C.last_name),
'enabled',
'disabled') AS account_status
...