gpt4 book ai didi

mysql - sql 字符串无法正确

转载 作者:行者123 更新时间:2023-11-29 17:28:18 26 4
gpt4 key购买 nike

我正在尝试从我的数据库获取一些数据。

看起来有点像这样

群组

groups_idgroups_namegroups_descriptiongroups_activegroups_hashgroups_entry_dateuser_idgroups_emailgroups_sms

CUSTOMERS_GROUPS

customers_hashgroups_hash

客户

customers_idcustomers_first_namecustomers_surnamecustomers_telephonecustomers_emailcustomers_telephone_activecustomers_email_activeclient_typecustomers_hashcustomers_entry_date

我想要 customer.groups_hash 和 groups.groups_name 采用串联形式。这是我的尝试...

SELECT * , GROUP_CONCAT( DISTINCT customers_groups.groups_hash
SEPARATOR '/' ) , GROUP_CONCAT( groups.groups_name
SEPARATOR '/' )
FROM customers
INNER JOIN customers_groups ON ( customers.customers_hash = customers_groups.customers_hash )
LEFT JOIN groups ON ( customers_groups.customers_hash = groups.groups_hash )
WHERE groups.groups_active ='1' GROUP BY customers.customers_entry_date

但它给了我一个零集......

最佳答案

问题出在你的where子句上。它必须是 on 子句的一部分:

SELECT * , GROUP_CONCAT( DISTINCT customers_groups.groups_hash
SEPARATOR '/' ) , GROUP_CONCAT( groups.groups_name
SEPARATOR '/' )
FROM customers
INNER JOIN customers_groups ON ( customers.customers_hash = customers_groups.customers_hash )
LEFT JOIN groups ON ( customers_groups.customers_hash = groups.groups_hash ) AND groups.groups_active ='1'
GROUP BY customers.customers_entry_date

关于mysql - sql 字符串无法正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50838922/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com