I have two tables as Table A and Table B.Table A contains few records with same emp_id and date as shown in below.but time column has different values.Now i wants to insert these two records as one record to the Table B.expected output of Table B is shown Below.
Table A
Table B [expected output]
This would be the sort of logic that you need to display that result. Not sure it will work exactly without testing it with your particular tables etc. This will also select the data and display it like that but wont insert it (dont know why you would need that)
SELECT
id,
emp_id
date,
MAX(case when row = 1 then time end) in1,
MAX(case when row = 2 then time end) in2
FROM
(
SELECT id, emp_id, date, time
row_number() over(partition by id) row
FROM TableA
) a
GROUP BY date;
Let me know if you have questions
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.