【发布时间】:2021-04-28 12:24:13
【问题描述】:
我有两张桌子(例如)
table1 将包含商店,有 2 种类型“糖果店”和“牙科店”。
每行包含有关客户在特定商店购买的信息
table1(购买):
+----+---------+------------------+-------+
| id | store | date of purchase | money |
| 1 | store 1 | 2016-01-01 | 10 |
| 1 | store 5 | 2018-01-01 | 50 |
| 2 | store 2 | 2017-01-20 | 10 |
| 2 | store 3 | 2019-02-20 | 15 |
| 3 | store 2 | 2017-02-02 | 20 |
| 3 | store 6 | 2019-01-01 | 60 |
| 1 | store 1 | 2015-01-01 | 20 |
+----+---------+------------------+-------+
table2(类型):
+---------+--------+
| store | type |
| store 1 | candy |
| store 2 | candy |
| store 3 | candy |
| store 4 | dental |
| store 5 | dental |
| store 6 | dental |
+---------+--------+
我希望我的查询返回这样的表:
+----+---------------+-----------------+---------------+
| id | the last place| the last date c |the last date d|
| 1 | store 5 | 2016-01-01 | 2018-01-01 |
| 2 | store 3 | 2019-02-20 | - |
| 3 | store 6 | 2017-02-02 | 2019-01-01 |
+----+---------------+-----------------+---------------+
在哪里
- [最后一个地方]是客户最后购买的店铺;
- [最后日期 c] - 在糖果店购买的最后日期
- [最后日期d]是最后在牙科店购买的日期
【问题讨论】:
标签: sql postgresql