[英]Select multiple rows into a single row one after the other in Postgres
我正在使用postgresql并有一个看起来像这样的表“ sometable”
id | ref_id | a_remarks | a_date | b_remarks | b_date
1 | 32 | 'send xyz' | 20/06/2014 | 'file send' | 22/06/2014
2 | 32 | 'send abc' | 25/06/2014 | 'file send' | 01/07/2014
但是在向用户显示时,我需要以这种方式显示
20/06/2014 Send xyz
22/06/2014 file send
25/06/2014 send abc
01/07/2014 file send
因此,我无法依次查看数据,因为它在不同的列中。 谁能帮我这个?? 提前致谢。
创建一个选择a_remarks和a_date的查询,将其与另一个选择b_remarks和b_date然后按id排序的查询合并。 如果删除ID很重要,则在子查询中创建并集,然后将ID放在外部查询中即可。 像这样...
SELECT t.date, t.remarks FROM (SELECT id, a_date AS date, a_remarks AS remarks FROM sometable UNION SELECT id, b_date AS date, b_remarks AS remarks ORDER BY id) t;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.