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

SQL MAX: max date from multiple locations same part

what I’m looking to find is that last or max date a part number was purchased from any store. so we can have so sales or sales and just give the max date: part date loc 123 8/1/2022 store 1 123 8/2/2022 store 1 123 null store 2 123 8/3/2022 store 3 result would be: part date Loc 123 8/3/2022

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

Select max entries in a range in SQL server

I have a salary column where I have to select between range of 10000 and 20000 and also the top rows of max salary. Column I have: Rows I want to select I can use top n rows but that will apply on to this column. What I want to do is, say if this column has 2 rows that

How do I select all columns that belong to one columns MAX() value in SQL?

I need to get values from different columns (in one record) where one column has a maximum value. How do I select the maximum value of one column and all the other columns from the same record? This only selects the highest value of the selected column Answer I can’t comment on other posters answers yet since my reputation isn’t

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

Advertisement