Sql 标头将取决于操作名称的更改
我有银行业务表和其他业务量表Sql 标头将取决于操作名称的更改,sql,postgresql,Sql,Postgresql,我有银行业务表和其他业务量表 Operation Id | name操作 -------------+---------------- 0 |转移 1 |注册 2 | BLIK 操作Id |金额 -------------+-------- 0 | 15,000 1 | 53,000 2 | 200 E.t.c 我应该写一个查询,以列的形式显示操作名称和金额。我写了这样的东西: Select case id_o
Operation Id | name操作
-------------+----------------
0 |转移
1 |注册
2 | BLIK
操作Id |金额
-------------+--------
0 | 15,000
1 | 53,000
2 | 200
E.t.c
我应该写一个查询,以列的形式显示操作名称和金额。我写了这样的东西:
Select
case id_operacji
when 0 then amount
end as 'transfer',
case id_operacji
when 1 then amount
end as 'registration ',
case operation id
when 2 then amount of operation
end as 'BLIK'
from ...
作为对上述解决方案的响应,我收到的信息表明,主要问题是检查报头是否取决于操作名称的更改。有人能帮我怎么做吗?据我所知,您正在寻找两个表之间的连接:
select a.amount, o.name_operation
from operations o
join amounts a on o.operation_id = a.operation_id;
我不得不猜测表和列名,因为您没有披露真正的表结构。
作为“传输”
一开始是无效的SQL。这是一个示例。我想到了。