特定的合并sql中的2列(不包括其中一列) [英] Specific merge 2 columns in sql excluding one of them
本文介绍了特定的合并sql中的2列(不包括其中一列)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的桌子:
| user1 | user2 |
| 1 | 2 |
| 3 | 1 |
| 4 | 1 |
| 1 | 5 |
| ... | ... |
我想将此列合并为一,但在新合并的列中必须为数字,这与给定的数字不相等.那就是如果我在上表中使用此查询并给出数字1:
I wanna merge this columns into one, but in new merged column must be number, which not equals with one given. That is if I used this query on table above and give number 1:
SELECT CONCAT(user1, user2) AS user FROM table WHERE user1 = 1 or user2 = 1
我已经退回了这个
| user |
| 12 |
| 31 |
| 41 |
| 15 |
| .. |
何时应返回此值:
| user |
| 2 |
| 3 |
| 4 |
| 5 |
| ... |
1是一个示例.该怎么做?
1 is an example. How to do that ?
推荐答案
SELECT IF(user1 = 1, user2, user1) AS user
FROM table
WHERE user1 = 1 OR user2 = 1
这篇关于特定的合并sql中的2列(不包括其中一列)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文