Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
1 answer
114 views

Max() and Min() have different behaviours?

Why is the behaviour of min() different from max()? Select max(My_Date) over (order by My_Date) as Max_Datum , min(My_Date) over (order by My_Date) as Min_Datum From ( Select dateadd(m,-1,...
Merlin Nestler's user avatar
0 votes
3 answers
66 views

Select all value except min value and add corresponding min value in another column

Consider this table: id text 101 Black 102 Black 103 White 104 White 105 White How one could select all the ids except the min id, but also add the corresponding min value in another column? So the ...
nzskra's user avatar
  • 165
-3 votes
1 answer
70 views

T-SQL Min and Max

I am trying to get the min and max values from the results of the first part of my query: SELECT DISTINCT a.[Recording Date], REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(...
DDJE's user avatar
  • 1
0 votes
3 answers
85 views

How to select earliest date with condition

Is it possible to select the earliest Open_Date from the below table on the condition that Sub_ID's Status is either Open or Complete? Order_ID Sub_ID Open_Date Close_Date Status Status_Update_Date ...
dexter_walking's user avatar
0 votes
2 answers
64 views

How to get MIN(opened_date) and all Open Records

I have some data that looks like this: Number CI PLUGIN Opened Date State 1 XYZ A123 1/1/2023 Closed 2 XYZ A123 2/1/2023 Closed 3 XYZ A123 3/1/2023 Closed 4 XYZ A123 4/1/2023 Open 5 XYZ A123 5/1/2023 ...
Chrissy Scott's user avatar
-3 votes
2 answers
792 views

SQL min and max function not displaying proper results [closed]

I am having a problem with using the MIN and MAX function in Microsoft SQL Server The problem is regarding MIN and MAX functions displaying the results incorrectly. My query is like this: SELECT ...
KronikusGladnikus's user avatar
0 votes
2 answers
349 views

How to get rows with minimum ID on a multiple columns query

I have a table like this: Id Type multiple columns (a lot)... 1 50 2 50 3 50 4 75 5 75 6 75 I need to get only the rows with the older (min) id as a part of my query. The result should include all the ...
Fernando Álvarez's user avatar
0 votes
1 answer
53 views

Selecting max value between columns and replacing non min values to 0

I have 4 columns in table that each have different category values. I would like to find the maximum value between the columns and keep only that while turning all other values to 0. How can I go ...
Trevor M's user avatar
1 vote
1 answer
67 views

How to extract first min value and second min value within a space of time

I am trying to select customers who have spent amount less than 15 in two consecutive occasions, first purchase must be less than 15, second purchase must be less than 15 and must be 90 days or more ...
Mikko's user avatar
  • 29
0 votes
0 answers
31 views

Effectively mimic T-SQL LEAST in earlier version (2017)? [duplicate]

So, I got myself in a situation where I have 36 columns and need to essentially do a "MIN" on ALL those columns. Not a MIN by grouping, rather, what I need is what the 2022-and-after LEAST ...
Isaac's user avatar
  • 17
0 votes
2 answers
450 views

Find sum of hours for each date worked

I have a table of timesheet entries set up like this: id job_id employee_id hours_worked date_worked 1 1 111 8 2022-10-01 2 1 222 8 2022-10-01 3 1 222 8 2022-10-02 4 2 222 8 2022-10-03 5 2 111 8 2022-...
KM_MS's user avatar
  • 21
-1 votes
2 answers
430 views

Select min (datetime) and max(datetime)

My data is like this | id. | date. | datetime. | |:---- |:------:| -----:| | 123 | 2022-01-02 | 2022-01-02 8:00:00 | | 123 | 2022-01-02 | 2022-01-02 10:00:00 | | 123 | 2022-01-03 | 2022-01-03 ...
Muhamad Akmal's user avatar
1 vote
3 answers
83 views

How to use min() together with other column in SQL

I am building an application consisting of an SQL backend and several microservices that communicate with this backend. I am trying to get as little data as possible from the database over the wire so ...
noob's user avatar
  • 13
0 votes
1 answer
43 views

Finding the Lowest ID Based On the Status Of Another Column? [duplicate]

There are a lot of tips on the use of the MIN() function, but the situation below is more complicated because of multiple conditions. Each [Project] can have multiple [Work Order]s and each [Work ...
Sudenga-Steve's user avatar
0 votes
1 answer
38 views

Select min BeginDate from duplicates [duplicate]

select [BK_Vendedor] ,[NIF] ,[BeginDate] ,[EndDate] from ( select [BK_Vendedor] ,[NIF] ,[BeginDate] ,[EndDate], count(*) over (partition ...
rafamaniac's user avatar

15 30 50 per page
1
2 3 4 5
10