|
我有以下两个表,你也可以SQL fiddle这里发现: :) J4 f; n' z, H
## Sent Orders ## CREATE TABLE Send_Orders ( Send_Date DATE, Product TEXT, FlowType TEXT )INSERT INTO Send_Orders (Send_Date,Product,FlowType) VALUES ("2017-05-23","roduct A","Send"), ("2018-09-10","roduct B","Send"), ("2018-12-14","roduct B","Send"), ("2019-01-03","roduct A","Send"), ("2019-02-15","roduct C","Send"), ("2017-09-04","roduct C","Send"), ("2019-01-09","roduct A","Send"), ("2019-02-16","roduct A","Send"), ("2019-02-12","roduct A","Send"), ("2019-02-15","roduct C","Send"), ("2018-01-03","Product B","Send");## Return Orders ## CREATE TABLE Return_Orders ( Return_Date DATE, Product TEXT, FlowType TEXT )INSERT INTO Return_Orders (Return_Date,Product,FlowType) VALUES ("2017-06-24","Product A","Return"), ("2018-07-11","Product B","Return"), ("2018-12-18","Product B","Return"), ("2019-02-01","Product A","Return"), ("2019-02-22","Product C","Return"), ("2017-10-18","Product C","Return"), ("2019-04-12","Product A","Return"), ("2019-02-19","Product A","Return"), ("2019-03-25","Product A","Return"), ("2019-04-19","Product C","Return"), ("2018-05-17","Product B","Return");现在,我想运行一个查询并将列合并到一个称为的列中Send_Date,因此,结果如下:Return_Date``Event_Date z$ c% I0 y# Y& o1 Y% p/ D& J
Event_Date Product FlowType2017-05- Product A Send2017-06-24 Product A Return2018-09- Product B Send2018-07-11 Product B Return: : : : : : : : : : : :::: : : : : : : : : : : :到目前为止,我可以加入两个表,但是日期显示在两个单独的列中:
9 F( J9 L! q2 E( ]& M; VSELECT s.Send_Date,r.Return_Date,s.Product,s.FlowTypeFROM Send_Orders sJOIN Return_Orders r ON r.Product = s.ProductGROUP BY 1,2;我需要在SQL将它们合并成一列是什么变化?" }: R- P& Z1 v+ p* t
: R6 l7 t( ]+ J8 F 解决方案: |
|