英文:
Group_CONCAT CASE multiply outputs
问题
GROUP_CONCAT(CASE WHEN t3.ship=1 AND t4.item=0 THEN CONCAT(t2.item_no, '. ', t2.item_name) END ORDER BY item_id SEPARATOR '<br>') `My Item List`
期望输出:1. Lamp
<details>
<summary>英文:</summary>
I have an SQL query with this line:
GROUP_CONCAT(CASE WHEN t3.ship=1 AND t4.item=0 THEN t2.item_name END ORDER BY item_id SEPARATOR '<br>') My Item List
Output Now: Lamp
It works perfectly, however I want to list out the item's number which is stored in item_no column.
Expected Output: 1. Lamp
I tried to add something like this, but didnt work:
GROUP_CONCAT(CASE WHEN t3.ship=1 AND t4.item=0 THEN t2.item_no, '.' ,t2.item_name END ORDER BY item_id SEPARATOR '<br>') My Item List
How can I achive this?
</details>
# 答案1
**得分**: 0
你必须使用 [`CONCAT()`][1] 连接 `item_no`、`'.'` 和 `item_name`:
... THEN CONCAT(t2.item_no, ''.', t2.item_name) END ...
[1]: https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_concat
<details>
<summary>英文:</summary>
You must concatenate `item_no`, `'.'` and `item_name` with [`CONCAT()`][1]:
... THEN CONCAT(t2.item_no, '.', t2.item_name) END ...
[1]: https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_concat
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论