Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [max]

Finding the maximum value in a group of items

0
votes
1answer
205 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
42 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
85 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
32 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
705 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
646 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
39 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
35 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 ...
0
votes
0answers
64 views

Why query plans is different for queries with the same WHERE Clause?

We use PostgreSQL. We have TABLE_A in our database table has a lot of rows - 500 millions table has a several columns: COLUMN_ID, COLUMN_2, COLUMN_3, COLUMN_4 COLUMN_ID is primary key so it is NOT ...
3
votes
2answers
355 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
37 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 - :...
0
votes
0answers
71 views

Postgresql optimize query for max() - min() with datetime

I have a hispoint table with fields (point_id, value, datetime). I want to make a query for max(value) - min(value) where point_id = num and datetime between start and end. The hispoint table has ...
11
votes
2answers
7k 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 ...
3
votes
1answer
278 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
136 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
823 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
52 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
3k 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
4k 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
vote
2answers
137 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 ...
2
votes
2answers
9k 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
6k 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
175 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
1k 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
30 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
154 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
335 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
2k 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.
0
votes
2answers
6k 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
548 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
10
votes
4answers
22k 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
38 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
65 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
1answer
3k 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
59 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
1k 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
69 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
205 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 ...
1
vote
3answers
195 views

How can i return the date of max id?

I want to select the max id_product and date that corresponds to this max id. my problem is that it returns the max id_ product with a different date. I can't use the max(date) because it will return ...