-1

I have a table A:

A.date | A.price
2013-10-01 | 5000
2013-10-02 | 5000
2013-10-03 | 5000
2013-10-04 | 5000
2013-10-05 | 5000

and table B:

B.date | B.price
2013-10-01 | 3500
2013-10-03 | 1600

In output I would like to receive the following information:

2013-10-01 | 3500
2013-10-02 | 5000
2013-10-03 | 1600
2013-10-04 | 5000
2013-10-05 | 5000

How to do it, help!

4

1 回答 1

4

您可以使用 LEFT JOIN,并且可以尝试将表 A 与表 B 连接:

SELECT
  A.date,
  COALESCE(B.price, A.price)
FROM
  A LEFT JOIN B ON A.date=B.date

如果连接不成功,B.price 将为 NULL,否则它将有一个值。使用 COALESCE() 您可以获得第一个非空值。

在此处查看小提琴。

于 2013-07-01T10:08:56.977 回答