mysql - SELECT 在 MySQL 中连接 N:N 关系
问题描述
我有这 3 个表,它们将产品及其类别置于 N:N 关系中:
products:
product_id | product_name
1 | Apples
2 | Shrimps
3 | Water
categories:
cat_id | cat_name
1 | Vegetable
2 | Seafood
3 | Fresh
4 | Drinks
5 | Non-alcohol
products_to_categories:
product_id | cat_id
2 | 2
2 | 3
3 | 3
3 | 4
3 | 5
...
我想SELECT CONCAT...
有这样的行:
product_id | product_name | product_categories
2 Shrimps Seafood, Fresh
3 Water Fresh, Drinks, Non-alcohol
有没有办法在 MySQL 中做到这一点?
解决方案
推荐阅读
- php - 如何使用 PHP 和 MySQL 解决 FizzBuzz 问题?
- scikit-learn - np.zeros(self.shape,dtype=self.dtype,order=order)
- javascript - 仅在threejs中检测WebGL Canvas上的触摸
- python - 在python中显示不同时间的节点连接
- html - 如何在堆叠图标内居中元素
- ios - 如何打开watchos的网址
- vue.js - 为什么像`beforeLeave`这样的过渡方法在nuxt中不起作用
- javascript - 使用 .closest() 比较最近的 id
- c - Linux C 套接字 - recvmsg - 获取源 ifindex
- python - 如何在整个音频文件上调用 librosa 函数?