0

I want to display the data in table 1 as in the form of table 2 in oracle.

Table 1.

enter image description here

Table 2 (Required).

enter image description here

gotqn
  • 42,737
  • 46
  • 157
  • 243
xajid
  • 1
  • 2
  • Does this answer your question? [Oracle SQL pivot query](https://stackoverflow.com/questions/4841718/oracle-sql-pivot-query) – astentx May 31 '23 at 05:57

1 Answers1

0

It should be something like this:

SELECT T1.Sno
      ,T1.Name
      ,TO_CHAR(TRUNC(TO_DATE(T2.AttendanceTime, 'MM/DD/YYYY HH24:MI') - TO_DATE(T1.AttendanceTime, 'MM/DD/YYYY HH24:MI')), 'HH24:MI')
FROM my_table T1 
INNER JOIN my_table T2
     ON T1.Sno= T2.Sno-1

You just need to join the table twice.

gotqn
  • 42,737
  • 46
  • 157
  • 243
  • in T1.n, what is "n"? – xajid May 31 '23 at 06:20
  • I mean `Sno`, and I am relying on that the rows for one name come one after another. But in your real data, the situation can be different. For example, you can join by `Name` instead - if it's unique. Or use window function to generate new row_id on which to join data. – gotqn May 31 '23 at 06:23