我有 3 张桌子。第一个包含customer_group_id
and account_number
,将每个组链接到一个帐户。第二个包含customer_id
和customer_group_id
,将每个客户链接到一个客户组,第三个包含按客户 ID 的客户描述。
我想获取帐户中所有客户的客户信息customer_group
。我使用的语法如下:
SELECT *, CONCAT(c.firstname, ' ', c.lastname) AS name, cgd.name AS customer_group
FROM customer c
LEFT JOIN customer_group_description cgd
LEFT JOIN customer_group cg
ON (c.customer_group_id = cgd.customer_group_id)
WHERE cg.account_number = '1'
请,任何帮助将不胜感激。
customer_group:
--------------------------------------
| customer_group_id | account_number |
--------------------------------------
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
--------------------------------------
customer_group_description
--------------------------------------
| customer_group_id | name |
--------------------------------------
| 1 | group1 |
| 2 | group2 |
| 3 | group3 |
--------------------------------------
customer
-----------------------------------------------
| firstname | lastname | customer_group_id |
-----------------------------------------------
| john | smith | 1 |
| black | smith | 1 |
| gold | smith | 2 |
| bob | dylan | 3 |
-----------------------------------------------
我希望这将有助于更好地澄清我的问题。这个想法是获取帐号 1 下的所有用户。
谢谢你。