【发布时间】:2021-11-30 19:07:37
【问题描述】:
这是我的桌子:
| pkey | Name | Report_to |
|---|---|---|
| 11 | abc | 12 |
| 12 | def | 13 |
| 13 | sdf | 11 |
| 14 | dfg |
我想要这样的输出:
| Name | Report_to |
|---|---|
| abc | def |
| def | sdf |
| sdf | abc |
| dfg |
我已经试过了:
SELECT CONCAT( CASE WHEN `Report_TO` = `PKEY` THEN Name ELSE CONCAT( "no one " ) END )
现在我得到输出:
| Name | Report_to |
|---|---|
| abc | no one |
| def | no one |
| sdf | no one |
| dfg | no one |
是否可以得到我想要的输出。
【问题讨论】:
-
MySQL SQL Server - 请更正您的标签。
-
您使用的是 MySQL 还是 MS SQL Server?
-
你想要一个 self (left) join,没有 concat。
-
我正在使用 mysql @jarlh
标签: mysql concatenation string-concatenation