Skip to content
Advertisement

Tag: max

Trying to find the max observation by group

I have the below code where I am trying to find a patients injury level and whether it is between 1 and 5 or 6 and 10. I have used the ‘case when’ clause below. The issue is, some patients have multiple injury levels. Is there a way for me to only get the max injury level and ignore the

join equal or max

I want to join two tables by ‘EmployeeId’ and ‘CalendarMonthId’, but problem is that I want to connect record with the bigest CalednarMonthId if not exist equal. I use Azure Synapse SQL pool. Example data and code Base on this data I have problem with connect table: emp_contr, row: EmployeeId:1, CalendarMonthId:202205 with row from table contr from the same user

SQL to find local count max per primary key

I have a table with PK CustomerId + type. Each customer has a few types. For each customer I want to get type which repeated the most for this customer. I’ve tried to create a column “count” but I want to get the local maxs, and not a global max for the whole col. Is there a native way to

How to do MAX COUNT so Query returns 1 Result SQL

I have the following query: Which returns the following results: Id EmailDomain UserCount 1 @yahoo.com 1 1 @gmail.com 4 2 @hotmail.com 1 3 @aol.com 1 3 @comcast.com 1 I need the Ids and the Email Domains for a later query, but I don’t want multiple email domains. So I want my results to look like this: Id EmailDomain UserCount 1

Get max date based on another column in SQL

I have a table variable which consists of columns id, date and status as shown below And follows is the sample data Also declared a variable as shown below. From this table I need to get the row which containing the maximum value of date( MAX(dates) ) where status is ‘ABC’, from the above sample values, I should get the

SQL query for entries of last N jobs

I have the following table: etc, so basically jobs keep adding entries concurrently I am looking for an efficient query to return all entries of the latest (by time) N jobs So find the first (by time) entry for each job, then using that get the latest N jobs with all their entries So for the above table and N=3

Advertisement