Questions tagged [max]

Finding the maximum value in a group of items

Filter by
Sorted by
Tagged with
-1 votes
0 answers
21 views

I am trying to change queries to parameterized queries in PostgreSQL and the below query is not working

alert_log_sql = "select t.time_period, t.cpu_util from (SELECT time_bucket($1, time) AS time_period, TRUNC ($2(cpu_used_percent), 0) AS cpu_util FROM system_stats WHERE time > now() - ($3)::...
user avatar
  • 1
4 votes
2 answers
1k views

How to retrieve the maximum value and its corresponding date in a table

I'm trying to figure how to retrieve minimum/maximum values and minimum/maximum dates from a data set, but also the date value that corresponds to each minimum/maximum value. Example Data CREATE TABLE ...
user avatar
0 votes
0 answers
52 views

Select Max record from last 6 hours from the table

I have multiple records for sample locationId for Same date. But createDate and time different. I need to take the max record from the last 6 hours. If the same locationId has record which is time is ...
user avatar
0 votes
2 answers
84 views

How to get the second highest value per group?

Getting the second highest value from a table has been solved many times, but I'm looking for the second highest value in each group. Given this table: +----+-----+ | A | 10 | | A | 20 | | A | ...
user avatar
  • 455
0 votes
3 answers
44 views

Statement of total precipitation for each hour, day or month

I store the data from the rain gauge in mySQL and needed help with listing the data. I save the data every 5 minutes and use the save date in the form of a timestamp. At the end of each hour, ...
user avatar
0 votes
3 answers
63 views

Find Max() updated time for a group of users

Database is MariaDB 10.3.25 I have 2 columns that are relevant: UserID and LastUpdate UserID consists of user@domain LastUpdate is a date field. Here is my issue - I have the current query: select a....
user avatar
2 votes
2 answers
792 views

Choosing values from multiple columns based on latest value of one column

I have an Azure Cosmos DB that contains columns DateTime, userName, temperature, and bloodPressure, plus many other columns. There are several distinct userName values, and each userName has ...
user avatar
  • 143
0 votes
1 answer
44 views

why is there an index range scan on max() query?

I have a table that logs the transmission of data to another system. create table transfer_log (id number(10), fk_data number(10), first_sent_time ...
user avatar
0 votes
1 answer
83 views

SQL Only display data with Max latest date date

tracking_id | date_action | action_id 1 | 2021/01/24 | 4 1 | 2021/01/26 | 3 2 | 2021/01/25 | 67 2 | 2021/01/24 | 8 4 | 2021/01/27 | 10 5 ...
user avatar
0 votes
2 answers
44 views

Max of a query which is inside

Create a database for a drone delivery startup that distributes pizzas via drones. The startup has partnerships with several drone manufacturers and pizza shops. The entities of interest to the ...
user avatar
0 votes
1 answer
34 views

Query returns all values instead of the row of the one with the max value

I have this database https://pastebin.com/WWRxApWn I need the row of the product with the greatest unitprice. I did: SELECT id, MAX(unitprice) FROM product GROUP BY id; Instead, it returned every row ...
user avatar
0 votes
1 answer
24 views

How to select maximum row value using optimal way

I have a large table: +----+-----------+------------+--------+--------+--------+ | Id | lClientId | datAccess | lProp1 | lProp2 | lProp3 | +----+-----------+------------+--------+--------+--------+ | ...
user avatar
  • 11
4 votes
3 answers
2k views

Why is there no max(uuid)/min(uuid) function?

Why can I use a UUID to sort rows: SELECT uuid_nil() ORDER BY 1; But I cannot compute the maximum value: SELECT max(uuid_nil()); [42883] ERROR: function max(uuid) does not exist Hint: No function ...
user avatar
  • 237
0 votes
1 answer
25 views

Need to Bring Back most Recent Departure Date from Sales table for Customers in Recipient table

Looking at 3 Tables - Recipient, HouseholdScores, Sales. I need to bring back the most Recent tsDepart (departure date) from sales for the iCustomerId in the Recipient Table. There is no Depart date ...
user avatar
1 vote
1 answer
206 views

How to get MAX numeric value from a column with char values in MySql

I would like to know how can I get the max value only within the numeric values in a column with char values in a MySql database: Supposing the column is as follows: col --------- ALL USD ...
user avatar
  • 175
0 votes
0 answers
35 views

MAX with group by by 2 columns

I have a query create table film_actor ( actor_id integer, film_id integer); create table film ( film_id integer, title varchar); create table actor ( actor_id integer, ...
user avatar
0 votes
0 answers
35 views

I'm having trouble generating a list of downloadable items (data from three tables) with a column showing most recent download time for each

I am using the following query to generate a comprehensive download log with data from multiple tables (reduced to three for this example): SELECT wp_download_log.ID ,wp_download_log....
user avatar
0 votes
0 answers
47 views

query start, due, complete dates for first and last time phases from phase tracking table

linked excel file I have a phase tracking table which consists of the fields record id, phase name, record order number etc: RECORD_ID,phase,RECORD_ORDER,SUBMITTED_DATE,DUE_DATE,COMPLETED_DATE 1657,...
user avatar
  • 11
0 votes
1 answer
25 views

Postresql, max returns all rows with same ids

System PostgreSQL 11.5 (Ubuntu 11.5-1.pgdg19.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 8.3.0-6ubuntu1) 8.3.0, 64-bit Issue Need return one max value from table for every product_id (1 ...
user avatar
  • 153
1 vote
1 answer
670 views

DB2 SUM of MAX values, single table

I have looked through many of the questions asked and answered but can't seem to find my answer, even kludging the provided answers into my queries - most usually fail, the remainder provide garbage ...
user avatar
-1 votes
1 answer
38 views

How can I get the max value for each column?

If data of table like this, [co1:varchar][col2:varchar][col3:varchar][col4:timestamp] And, Follow is data example. 224 / 755 / 542 / 2019-05-23 10:12:23 230 / 741 / 530 / 2019-05-23 10:12:23 221 / ...
user avatar
0 votes
1 answer
11k views

Select ONLY Max(date) when there's repeating dates

Here is a sample of the data contained in my Tracking table: tracking_id date_action action_id staffing_id ------------- ----------- ----------- ----------- 1 2019/03/04 4 ...
user avatar
  • 33
4 votes
5 answers
7k views

Select unique records from multiple records based on max date

I have table like below +----+----------+-----+-------------+--------+ | ID | ADDR | IND | update_Date | Sq_NBR | +----+----------+-----+-------------+--------+ | 1 | PHYSICAL | Y | 11-Oct ...
user avatar
  • 129
1 vote
1 answer
77 views

What is the function that determines the maximum value in a series?

Say I have a table with columns C and D (among others but these are the relevant ones) with the date type. I am instructed to update the values in C to be 90 days before its corresponding value in D, ...
user avatar
  • 113
0 votes
2 answers
87 views

I only want one maximum value but it returns all the rows [closed]

I need help with this query. I'm trying to get a value for a customer that spends the most amount every month in 2018 but it doesn't work: PROMPT 'Customer that has Spent the Most on Specific Month' ...
user avatar
  • 11
0 votes
3 answers
39 views

Get Primary records where N most recent Secondary records match condition

I want a list of Authors (primary records) whose 2 most recent Books (secondary records) are best sellers. INSERT INTO Authors (`author_id`, `author_name`) VALUES (41, 'Heida Palffrey'), (...
user avatar
2 votes
2 answers
2k views

Get related row based on two MAX Values

I bumped into a use case where I wanted to write a SQL query to retrieve a row based on 2 MAX values of the table. I tried a couple of combinations but no luck as of yet. Here's a sample table and the ...
user avatar
0 votes
1 answer
2k views

MySQL - maximum of sum over different months [duplicate]

I have a table called commodities where I have nature_of_goodscolumn in it. nature_of_goods contains all the different types of goods like machinery, household etc. I have another column called as ...
user avatar
1 vote
1 answer
49 views

Max values on a group of fields

Does anyone know how can I select rows that contain maximum value for some group of fields based on some criteria? For instance, let's say I have the following table: Table1: ID fieldA fieldB ...
user avatar
  • 13
0 votes
1 answer
39 views

How can I find state name which has the most vehicle accidents in the database?

I have a table "ACC_DATA" that has the following columns: ACCIDENT_ID, STATE_CODE, ACC/DATE and a second table "US_STATES" which has the following columns: STATE_CODE and STATE_NAME Each accident ...
user avatar
  • 117
4 votes
2 answers
1k views

select MAX() from MySQL view (2x INNER JOIN) is slow

I want to optimize my MySQL view v_booking. At the moment I am wondering about the following issue: My queries Query 1 is slow (47,48 sec): SELECT MAX(Snapshot_Nummer) FROM v_booking; Query 2 is ...
user avatar
  • 143
0 votes
1 answer
42 views

Form groups computing max - min depending on number of peers

This is table: CREATE table point ( datetime timestamp, value float) I have data in some range of time 7:00 - 7:15: 0 5 : 5 7:15 - 7:30: - - : null 7:30 - 7:45: 7 - :...
user avatar
13 votes
2 answers
23k views

Understanding varchar(max) 8000 column and why I can store more than 8000 characters in it

From this Microsoft doc,+ n defines the string length and can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes (2 GB). The storage size is the actual ...
user avatar
2 votes
1 answer
1k views

MySQL Grouping Data Together From Same User

I need a database guru. I'm trying to solve a problem that I'm pretty sure can be solved with a simple query I cant figure out. First, this is the table ve_messages: MessageID | RecieverID | SenderID ...
user avatar
  • 65
1 vote
2 answers
897 views

MySQL query: select max(A) and use MAX(pkey) if multiple max(A) records exist

I've been trying to find a solution for this problem using just 1 join. Is it possible? table: pkey | uid | A | B | C 100 | 1 | 5 | 2 | 101 | 1 | 5 | 3 | 'should find this' 102 | 1 | 4 | 6 ...
user avatar
5 votes
1 answer
4k views

What would be the maximum number of records that can be indexed with a three levels B-tree ? B+ tree?

I am learning dynamic tree-structure organizations and how to design databases. Consider a DBMS with the following characteristics : file pages with size 2048 bytes pointers of 12 bytes page header ...
user avatar
0 votes
2 answers
132 views

MySQL: How to get the maximum disposition and the maximum date from my database

I want to get the top disposition of every ID where 1 is the lowest and 13 is the highest, however when there are IDs with similar disposition (e.g. ID #2 having multiple dispositions of '9') I cannot ...
user avatar
0 votes
1 answer
14k views

Finding row with Max value with inner join and sub-query

I need to SUM the total values of each student using INNER JOIN and then find the row with maximum value. I have used the below query to find the SUM of each student and sort in descending order ...
user avatar
  • 13
4 votes
2 answers
17k views

Find Max Value for each month for the last 3 months, properly

I have a query going that gets data for an ID for the last 3 months. I need to tweak it so I get the highest value for each of the three months. I've tried a couple of things with the aggregate ...
user avatar
-1 votes
2 answers
168 views

Refining Productivity & Efficiency Query

I'm trying to write a query that is, in effect, a Productivity and Efficiency Report for measuring the statistics of those of us (such as myself) who type up the paper work orders that our mechanics ...
user avatar
5 votes
2 answers
25k views

Return document that has $max value in specific field using mongodb

I have a json file that has some football results. I need to calculate which team won the most away games, and how many wins there were. My query is this: db.football.aggregate( {"$unwind": "$rounds"...
user avatar
  • 183
-2 votes
2 answers
16k views

Why is Max Date not working?

I have a simple query that I just want to return the most recent date for. I can't figure out why I can't do this:
user avatar
  • 1
1 vote
1 answer
518 views

Why is the value - despite of using GREATEST() - still out of range?

I tried the following to decrease a counter after a post was deleted by using GREATEST() so it does not result a negative value: SELECT GREATEST(0, posts - 1) FROM users WHERE id = 123 but it ...
user avatar
  • 133
0 votes
2 answers
6k views

Finding the name of the supplier that supplies the most parts

I have the following schema: Suppliers(sid: integer, sname: string, address: string) Parts(pid: integer, pname: string, color: string) Catalog(sid: integer, pid: integer, cost: real) Now what I'm ...
user avatar
0 votes
1 answer
69 views

Returning 1 Max Value when Some Counts Are Equal in Access

I'm building a database that needs to return peak traffic data for Month-over-Month and Year-over-Year Comparisons in Access. We are trying to determine what our busiest Monday is, Tuesday, Wednesday, ...
user avatar
1 vote
2 answers
249 views

max(max(col1), max(col2), ...) does not work

I have a table with three integer columns: select max(col1), max(col2), max(col3) from mytable I want the max of both three columns. But this does not work: select max(max(col1), max(col2), max(...
user avatar
  • 1,331
2 votes
1 answer
531 views

MySQL NDB cluster maximum data size

According to the limitations outlined at http://dev.mysql.com/doc/refman/5.7/en/mysql-cluster-limitations.html, there can only be 48 data nodes. Does that mean, with number of replicas 2, I can ...
user avatar
1 vote
1 answer
5k views

How to UPDATE NULL values by MAX()+1?

I want to assign values to null cells of a column as UPDATE table 1 SET number = MAX(number) + 1 WHERE number IS NULL but mysql return error Invalid use of group function.
user avatar
  • 4,169
1 vote
2 answers
14k views

MIN / MAX values with Date

I am trying to get the MAX and MIN values for the current month and the dates for these values. I am getting the MAX and MIN values but I am not getting the dates for these values. Instead I get the ...
user avatar
2 votes
5 answers
2k views

How to get one MAX() between SUMs of several columns in SQL? [closed]

I need to select MAX() between SUM(Math), SUM(English), SUM(Physics) Result must be: 19 | English
user avatar