mysql - sql字符串无法正确
问题描述
我正在尝试从我的数据库中获取一些数据。
有点像这样
组
groups_id
, groups_name
, groups_description
, groups_active
, groups_hash
, groups_entry_date
, user_id
, groups_email
,groups_sms
CUSTOMERS_GROUPS
customers_hash
,groups_hash
顾客
customers_id
, customers_first_name
, customers_surname
, customers_telephone
, customers_email
, customers_telephone_active
, customers_email_active
, client_type
, customers_hash
,customers_entry_date
我想要一个 concat 形式的 customers.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
但它给了我一个零集......
解决方案
问题在这里:
LEFT JOIN groups ON ( customers_groups.customers_hash = groups.groups_hash )
这可能应该是
LEFT JOIN groups ON ( customers_groups.groups_hash = groups.groups_hash )
(虽然尚不清楚哈希实际代表什么以及为什么没有桥接表链接表的 ID。我已在评论部分根据您的要求提出了这个问题。)
推荐阅读
- java - 如果我使用setter getter 在一种方法中设置值并且我可以使用getter 获得相同的值来获得它是可能的吗?
- ansible - 将主机作为变量从角色传递到下一个角色
- graphql - FaunaDB - 如何批量更新单个 graphQL 突变中的条目列表?
- python - 如何解决 500 内部服务器错误 mod_wsgi apache "importerror: No Module named 'django'
- c# - JET/Esent:SeekEQ 找不到多列索引和通配符的匹配项
- c++ - OpenCV 使用循环来总结图像错误的一部分?
- terminal - 对于在 centos 7 中找不到的 root 访问作曲家
- excel - Excel 对跨列满足多个条件的行进行计数和排序
- vector - 在使用余弦相似度识别新闻文章之间的相似性方面寻求帮助
- angular9 - SAP Spartacus 翻译