-2

There is a list of in and out transactions by vessel in the table

DB Example

What I'm hoping to achieve is for each out and in transaction to be on the same row.

Outcome

Table currently contains 7 million rows.

Thom A
  • 88,727
  • 11
  • 45
  • 75
  • What are you asking here exactly? What have you tried to get the results you are after? Why didn't it work? What is the logic to get said results? Sample data in a **consumable** format (not images) also greatly increase the chances of people helping you here; please don't expect use to transcribe your data. – Thom A Apr 12 '21 at 09:52
  • My suggestion: Filter only 'O' records, and use LEAD() to fetch the next vessel. – sagi Apr 12 '21 at 09:52

1 Answers1

0
SELECT
    *
FROM(
    SELECT
         T.[VESSEL]
         ,CASE WHEN T.TYPE = 0 THEN T.DATE ELSE '' END [DATE]
         ,CASE WHEN T.TYPE = 1 THEN T.DATE ELSE '' END [DATE_IN]
    FROM TABLE T ) AS L
GROUP BY L.[VESSEL],L.[DATE],L.[DATE_IN]