如何从包含多个值的列中获取包含自定义标题的新列中的数据,而不使用MYSQL中的字符串函数。
这是我使用多个连接提取的表的子集。
Product | Category -------- | ------------ MSI60000 | Sunglasses MSI60000 | Minimal Coding MSI60001 | Glasses MSI60001 | Minimal Coding MSI60002 | Sunglasses MSI60002 | Short Coding MSI60003 | Goggles MSI60003 | Long Coding MSI60004 | Goggles MSI60004 | Shortcoded
我希望从上表中实现这一点。
Product | Type | Coding -------- | ----------- | -------------- MSI60000 | Sunglasses | Minimal Coding MSI60001 | Glasses | Minimal Coding MSI60002 | Sunglasses | Short Coding MSI60003 | Goggles | Long Coding MSI60004 | Goggles | Shortcoded
给出https://docs.angularjs.org/guide/module#module-loading-dependencies类型的解决方案帮助了我,但它使用了我无法使用的字符串函数。
答案 0 :(得分:0)
您可以使用此查询 -
SELECT
Product,
MAX(IF(LOCATE('Coding', Category) = 0, Category, NULL)) AS Type,
MAX(IF(LOCATE('Coding', Category) > 0, Category, NULL)) AS Coding
FROM
tbl
GROUP BY
Product;
MSI60000 Sunglasses Minimal Coding
MSI60001 Glasses Minimal Coding
MSI60002 Sunglasses Short Coding
MSI60003 Goggles Long Coding
...但是有LOCATE功能。