Skip to content

Tag: sql-server

How to count rows by date for each of two values?

I have a large dataset in SQL Server that contains two date fields and a foreign key field (among others): I need a query that can count the number of rows for each day, but to count them for each distinct value in the type_id column. The closest I can wrap my brain around right now is returning the total

SQL Server: Counts and Percentage by Group

I’ve tried the suggestions I’ve found on SO and cannot get the results I’m looking for which is this: I am able to get the first two columns with this code: — What I’ve tried: Trying to use a calcuation in a subquery to represent the total number of rows in the table is beyond me…

SQL Row Data to Column Data in Join

Trying to wrap my tiny brain around how to write this query and I am at a loss: Current: How I would like it to look: If someone can point me to a function that could help me with this, it would be much appreciated. I already tried using: max(case when ….) and pivot() which I found in other articles,