Questions tagged [max]
Finding the maximum value in a group of items
51
questions
0
votes
1answer
26 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 ...
0
votes
2answers
42 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 ...
0
votes
1answer
19 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 ...
0
votes
1answer
21 views
How to select maximum row value using optimal way
I have a large table:
+----+-----------+------------+--------+--------+--------+
| Id | lClientId | datAccess | lProp1 | lProp2 | lProp3 |
+----+-----------+------------+--------+--------+--------+
| ...
0
votes
1answer
264 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 ...
0
votes
1answer
17 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 ...
1
vote
1answer
33 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 ...
0
votes
0answers
27 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,
...
0
votes
0answers
27 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....
0
votes
0answers
43 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,...
0
votes
1answer
22 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 ...
1
vote
1answer
371 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 ...
-1
votes
1answer
31 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 / ...
0
votes
1answer
6k 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 ...
4
votes
4answers
4k 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 ...
1
vote
1answer
67 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, ...
0
votes
2answers
86 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'
...
0
votes
3answers
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'),
(...
2
votes
2answers
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 ...
0
votes
1answer
1k 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 ...
1
vote
1answer
46 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 ...
0
votes
1answer
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 ...
4
votes
2answers
811 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 ...
0
votes
1answer
41 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 - :...
13
votes
2answers
19k 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 ...
2
votes
1answer
860 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 ...
1
vote
2answers
662 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 ...
5
votes
1answer
3k 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 ...
0
votes
2answers
120 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 ...
0
votes
1answer
12k 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 ...
4
votes
2answers
13k 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 ...
-1
votes
2answers
160 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 ...
4
votes
2answers
22k 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"...
-2
votes
2answers
13k 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:
1
vote
1answer
386 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 ...
0
votes
2answers
4k 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 ...
0
votes
1answer
50 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, ...
1
vote
2answers
217 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(...
1
vote
1answer
472 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 ...
1
vote
1answer
4k 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.
1
vote
2answers
13k 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 ...
2
votes
5answers
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
14
votes
4answers
50k views
Query to select max value on join
I have a table of Users:
|Username|UserType|Points|
|John |A |250 |
|Mary |A |150 |
|Anna |B |600 |
and Levels
|UserType|MinPoints|Level |
|A |100 |...
2
votes
2answers
39 views
List all articles with their amounts at a certain date+time
I've got a table with articles, and their stock amount changes:
TABLE stock_history:
+------------+---------------------+--------+
| article_id | amount_at | amount |
+------------+---------...
1
vote
2answers
69 views
Displaying a value associated with a maximum value
I have a PostgreSQL database for a supermarket (it's a toy problem) and I need to find which outlet has sold the most copies of each product and display it in a query which also shows the product name,...
1
vote
2answers
7k views
Find max and min date over multiple fields of the same record
I have a table with 4 distinct data-type fields. For each record, I need to find the max and min date over them.
That's easy to do for a set of records over a unique field. But how to do it in my ...
0
votes
1answer
62 views
Update an Oracle DB with a max number for the null rows
I have an Oracle db and I need to update some columns and one of them is an number that has to be some kind of an id - max number on that column. If I use something like this:
update ss_chest ssc
...
1
vote
2answers
2k views
Find Max(value) for each department using GROUP BY MYSQL
I want to print the name of student in each department who has the highest gpa,
Students(stuID: String, stuName: String, gender: String,
birthdate: Date, enterYear: Year, gpa: Float)
...
1
vote
1answer
74 views
What is the most compact way to calculate and then Update a maximum value for each day's data?
I have a database that stores records for each bundle of material. A sample is taken from each bundle and sent out for assaying (for lead and sulfur). I receive the assay data and write the assay ...
2
votes
1answer
1k views
Highest value of a row in MySQL
I searched and found many results using "Grep highest value of a row in MySQL" but I don't understand the results.
I have a row which primary key value is 4 and there are another 8 values.
Those are ...