我有一个包含四列subfield_id, submission_id, field_id, value
的mysql表
我提出了两个看法:
1。
SELECT submission_id,
MAX( CASE field_id WHEN '1' THEN value ELSE '0' END ) Usernumber,
MAX( CASE field_id WHEN '2' THEN value ELSE '0' END ) Company,
MAX( CASE field_id WHEN '3' THEN value ELSE '0' END ) Zipp,
FROM table
GROUP BY submission_id
结果表列:Submission_id, Usernumber, Company, Zipp
2。
SELECT submission_id,
MAX( CASE field_id WHEN '4' THEN value ELSE '0' END ) Usernumber1,
MAX( CASE field_id WHEN '5' THEN value ELSE '0' END ) Partnernumber
FROM table
GROUP BY submission_id
结果表列:Submission_id, Usernumber1, Partnernumber
Usernumber
和Usernumber1
是相同的数字
如何使用以下各列进行查看?
Usernumber, Company, Zipp, Partnernumber
答案 0 :(得分:0)
只需在单个查询中写下这个内容即可
SELECT submission_id,
MAX( CASE field_id WHEN '1' THEN value ELSE '0' END ) as Usernumber,
MAX( CASE field_id WHEN '2' THEN value ELSE '0' END ) as Company,
MAX( CASE field_id WHEN '3' THEN value ELSE '0' END ) as Zipp,
MAX( CASE field_id WHEN '5' THEN value ELSE '0' END ) as Partnernumber
FROM table
GROUP BY submission_id;
视图不会真正帮助您进行此查询。
编辑:
根据您的评论:
select *
from view1 v1 join
view2 v2
using (Usernumber);