mysql case when 字符拼接
时间: 2023-10-19 07:36:01 浏览: 129
在MySQL中,你可以使用CONCAT函数将字符串拼接起来。在CASE WHEN语句中进行字符拼接的示例如下:
SELECT CONCAT('类型:',
CASE orderType
WHEN 2 THEN 'C'
ELSE 'D'
END,
', 数量:', COUNT(*)) AS '结果'
FROM table
GROUP BY orderType;
在这个示例中,我们使用CONCAT函数将'类型:'和COUNT(*)的结果进行拼接,并在CASE WHEN语句中根据orderType的值返回不同的字母。最终结果中包含了拼接后的字符串和数量信息。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [case when和sum case when 写法及拼接字段](https://download.csdn.net/download/u013716500/9540627)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [sql 中case when 用法 和 拼接字符串](https://blog.csdn.net/weixin_36180385/article/details/113298417)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文