Home > database > Brothers help ah, have this demand, according to the date line into columns in the SQL, for a few da
Brothers help ah, have this demand, according to the date line into columns in the SQL, for a few da
Time:09-26
Quotation date this column is dynamic, the same date, conversion to produce only one column, the date, the more the more columns, of course, usually work under normal circumstances, a result table saw column will certainly not infinitely many columns,
CodePudding user response:
with t as ( Select "c3" as the name, the convert (date, '2019-10-4') as dt, 0.78 as price Union all select 'c2', '2019-10-4', 0.91 Union all select 'b2', '2019-10-20', 1.08 Union all select 'w3', '2019-10-20', 1.07 Union all select 'c3', '2019-11-4', 0.81 Union all select 'c2', '2019-11-4', 0.95 Union all select 'b2', '2019-11-20', 1.1 Union all select 'w3', '2019-11-20', 1.15 ) Select * from t The pivot (Max (price) for dt in ([2019-10-4], [2019-10-20], [2019-11-4], [2019-11-20])) p
You this is the simplest line column, to baidu pivot, as for the date not sure, their dynamic generate SQL commands can be exec after, the recent problems in turn a large line column,,,