有一个表: prov_dl
| ID | Code | Value |
+----+----------+-------+
| 2 | PRC | 0,1701|
| 2 | Stad | 3 |
数据以这种形式存储,即
按代码有几个条目
您需要以这种形式提取数据:
| ID | Stadya | Percent |
+----+----------+-----------+
| 2 | 3 | 0,1701 |
我尝试:
select id,
case when code='Stad' then Value end Stadya,
case when code='PRC' then Value end Percent
from prov_dl
| ID | Stadya | Percent|
+----+----------+--------+
| 2 | | 0,1701 |
| 2 | 3 | |
答案 0 :(得分:2)
使用max()
select id,
max(case when code='Stad' then Value end) as Stadya,
max(case when code='PRC' then Value end) as Percent
from prov_dl group by id