Skip to content

How to exclude a specific row from an SQL Count

I need to exclude a certain row from a COUNT in SQL Server. This is what I have: If I remove the last AND GuestStayDetails.GuestId != @GuestId; it gives me the expected COUNT however I must exclude one of the GuestIDs. Any suggestions? Answer It looks like you are looking for overlapping time intervals &#8212…

Can this be done as a SQL VIEW

I have a SQL Server table of Customer’s Events: There can be many EventTypes for the same customer in one day. EventTypes are like 1 – CheckIn 2 – CheckOut 3 – ExamStart 4 – ExamEnd Now I want to select Customers that are currently (today) on premises. That’s Clients who ha…

Calculate sum of duration SQL

I use the following sql to calculate the duration in the first query. CDate(TimeSerial(Val([EndTime])100,Val([EndTime]) Mod 100,0)-TimeSerial(Val([StartTime])100,Val([StartTime]) Mod 100,0))) AS …

SQL query using Sum() and count() functions

I’m trying to query in PostgresQL using the SUM function to get the total of 3 different row types (Root, Dynamic, Test). I used the Sum() function for the first attempt and the Count() function for the second attempt; both didn’t work sadly. I expect a syntax error (since I’m a beginner at …