Shh*_*Shh 2 sql postgresql join postgresql-9.1
我有两张桌子
table 1
col1 date
1 13/4/2014
2 15/4/2014
3 17/4/2014
5 19/4/2014
table 2
col1 date
1 13/4/2014
3 16/4/2014
6 18/4/2014
joining the two tables i should get
col1 date col2 date
1 13/4/2014 1 13/4/2014
2 15/4/2014
3 17/4/2014 3 16/4/2014
6 18/4/2014
5 19/4/2014
Run Code Online (Sandbox Code Playgroud)
重要的是date列应该排序,可以看到col数据6和5.这可能吗?
编辑:最后的表需要被命令col1.date并col2.date使得提前无论是在col1或col2将在连接表进行排序18/4/2014会之前,19/4/2014即使他们是在不同的列.我希望我明白我的观点.谢谢编辑:
table 1
1, "2014-04-03"
2, "2014-04-04"
3, "2014-04-11"
4, "2014-04-16"
5, "2014-04-04"
6, "2014-04-17"
7, "2014-04-17"
table 2
1, "2014-04-04"
2, "2014-04-11"
5, "2014-04-17"
Run Code Online (Sandbox Code Playgroud)
编辑:加入后应该是这样的
1 2014-04-03
2 2014-04-04
5 2014-04-04 1 2014-04-04
3 2014-04-11 2 2014-04-11
4 2014-04-16
6 2014-04-17
7 2014-04-17 5 2014-04-17
Run Code Online (Sandbox Code Playgroud)
select col1, date1, col2, date2
from
t1
full outer join
t2 on col1 = col2
order by coalesce(date1, date2), date2;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
128 次 |
| 最近记录: |