Sqlserver
 sql >> Teknologi Basis Data >  >> RDS >> Sqlserver

kueri sql - Dapatkan perbedaan waktu antara menggesek masuk - Gesek keluar untuk karyawan

select    empid,
          sum
          (
              datediff
              (
              MINUTE, 
              case when timesheet.timein < @timeframe_start 
                  then @timeframe_start  
                  else timesheet.timein end, 
              case when timesheet.timeout > @timeframe_end 
                  then @timeframe_end 
                  else timesheet.timeout end
              )
          ) as total_duration
from     (
         select    timein.empid, 
                   timein.swipe_time as timein, 
                   timeout.swipe_time as timeout
         from      tbltest timein
         left join tblTest timeout 
         on        timein.empid = timeout.empid
         and       timeout.eventtype = 'ex'
         and       timeout.swipe_time = 
             (
             select     MIN(swipe_time) 
             from       tblTest tcheck 
             where      tcheck.empid = timeout.empid 
             and        tcheck.eventtype = 'EX' 
             and        tcheck.swipe_time > timein.swipe_time
             )
         where      timein.eventtype = 'en'
         ) timesheet
where    timesheet.timein between @timeframe_start and @timeframe_end
or       timesheet.timeout between @timeframe_start and @timeframe_end
or       (
         timesheet.timein < @timeframe_start 
         and timesheet.timeout > @timeframe_end
         )
group by empid
order by 2 desc



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Cara cepat untuk menemukan penggunaan Objek DB di SQL Server 2008?

  2. Bagaimana cara mengganti nilai (null) dengan 0 output di PIVOT

  3. Bagaimana cara mengkonfigurasi SQL Native Client dengan PowerShell?

  4. Bagaimana Fungsi RIGHT() Bekerja di SQL Server (T-SQL)

  5. SQL Server:pilih baris terbaru yang jumlahnya cocok dengan nilai