說我有這個數據集「CONTAINS」是否有任何MySQL聚合函數?
user | group --------+------- [email protected] | A [email protected] | B [email protected] | A [email protected] | B [email protected] | A [email protected] | B [email protected] | C
我想這個轉換成像這樣的表:
user | IN_A | IN_B | IN_C --------+-------+-------+------- [email protected] | TRUE | TRUE | FALSE [email protected] | TRUE | FALSE | FALSE [email protected] | FALSE | TRUE | FALSE [email protected] | TRUE | TRUE | TRUE
我有:
SELECT user, IF(LOCATE('A', GROUP_CONCAT(group)) > 0, TRUE, FALSE) AS IN_A, IF(LOCATE('B', GROUP_CONCAT(group)) > 0, TRUE, FALSE) AS IN_B, IF(LOCATE('C', GROUP_CONCAT(group)) > 0, TRUE, FALSE) AS IN_C FROM users GROUP BY user
我想知道是否有更好的方法來知道一個聚合字段是否包含一個值,或者如果這是唯一的方法?
精美的作品! – 2016-09-14 22:13:11