Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Get Multiple Counts in one Statement

$
0
0

Hi there,

i'm stuck with a SQL-Statement.

This is my current statement:

SQL
Selectp.PNR,p.Name,p.Vorname,Count(pt.Soll)ASStundenFROM[data].[dbo].Personalpjoin[data].[dbo].[perstaginfo]ptonp.Nummer=pt.Persnrwherept.Jahr=2019andpt.Fehlgrundin(-2,7)andpt.Woche<=28andpt.Soll=7.5andp.aktiv=-1groupbyp.PNR,p.Name,p.VornameorderByStundenDESC,p.PNR

This will display the ID, Lastname, Name and hours.
|ID|Lastname|Name|Hours|

Right now it shows all the hours for the current week. I would like to show the hours from the previous, current and future hours as well. pt.Woche <= 28  this is the current work week

It should be:
|ID|Lastname|Name|OLD-Hours|CURR-Hours | FUT-Hours|

my guess is. i'll need multiple select statements with each count(*) filtered by week.
I just can't get it to work.

thanks in advance


Viewing all articles
Browse latest Browse all 4871

Trending Articles