Questions tagged [sql-max]
18 questions
2
votes
1 answer
Insert value in a column conditionally in MySQL
I have a table Persons with columns PersonId, FirstName, DeptId and City. The PersonId is a Primary Key.
By default on first insert, I want the first entry for the DeptId to have a value of 3000. And the subsequent entries should always increment on…

chatwa
- 23
- 3
2
votes
1 answer
Select multiple max values in mysql
Lets say i have two columns with diffrent values like this:
id |val
1 | 9
7 | 6
7 | 8
I want to return the max id, and then find the max value according to the id.
The row I return would be id: 7 and val: 8.
How would I write this in…

Elias Knudsen
- 315
- 2
- 9
1
vote
1 answer
How to select fix number of datapoints spread evenly over a time range
I am having a hard time creating a SQLite command that will return an evenly spaced out data points based on time if the number of data points is beyond 50.
Basically, I am having data stored every 30 seconds. However, if I want to see the data in…

philm
- 797
- 1
- 8
- 29
1
vote
1 answer
OFFSET and LIMIT are not working MAX in POSTGRES
The Follow query in the PGADMIN is giving me Nothing,
SELECT MAX(time) AS MaxID
FROM table_name
where column_name like 'valu_name'
OFFSET 1000 Limit 1000
Where as if I run the following query it gives me output
SELECT MAX(time) AS MaxID
FROM…

Shashi Preetham
- 23
- 7
1
vote
1 answer
Reordering the results of an SQL query using SQLite
I have a SQLite database that models Sanskrit nouns and has tables like this: (Sorry if it is very lengthy. I've tried to cut things down to the minimum necessary to understand this…

Jaldhar
- 279
- 1
- 10
1
vote
2 answers
In SQL how do I select the latest date that does not have a zero value in another column
I am trying to select the max date in a table that has a Booking Date and a Written Premium value for that date. I want the newest date that has Written Premium (not equal to Zero).
In the above table I want, or expect the 4th Row in my query…

BeRye
- 39
- 6
1
vote
1 answer
How to join two queries to make a subquery
I have a first query that give me a set of values and a second query that give me the maximum of this set of value.
I want to merge these two queries. I tried like this below:
First query:
SELECT SUBSTR(column, INSTR(column, ' ')+1,3)
from table …

Béa
- 101
- 2
- 9
1
vote
3 answers
How do I keep the order of my inner join in SQL?
I have the following command:
SELECT * FROM Posts P
INNER JOIN (SELECT DISTINCT ThreadId FROM Posts ORDER BY Time DESC) R
ON P.Id = R.ThreadId;
This command selects threads who contain the newest replies. Unfortunately the order of the threads…

moccajoghurt
- 159
- 9
1
vote
1 answer
Android Room getting yesterday's last record
I am storing date fields as date field in Android Room. Of course it converts to timestamp for storing the date in sqlite database.
It looks like this:
I need to get the latest record of yesterday and today's last record (today's will be another…

Tolgay Toklar
- 4,151
- 8
- 43
- 73
1
vote
1 answer
How to create a complex aggregate function in sqlite
Suppose I have the following table where there are two sets of observation dates (2015-01-01, 2016-01-01) in the first column. For each observation date, there are associated item_date and…

kyc12
- 349
- 2
- 15
1
vote
1 answer
SQLite UPDATE only one record matching a WHERE clause, with MAX on another filed
Need to modify the data in an SQLite database that has fields similar to:
hash (string)
modTime (long, time in ms)
data (any data, e.g. string)
I know the hash value of the record to set the data for (it's really xxHash of some…

gregko
- 5,642
- 9
- 49
- 76
0
votes
1 answer
Is there a way to organize by last invoice date by job?
I am fairly new to SQL and am looking for a solution. I am looking to find the best way to get the newest date from transaction date while being grouped by Job reference. Since these are different tables I am struggling someone please help.
SELECT
…

Nick1893
- 1
0
votes
2 answers
How to simplify SQL code for "MAX" operator
I was trying to solve one task and found the solution, it works, but the code is "awful" and duplicates itself, may be someone can just help me with that?
SELECT b."N",b."ID",max(b.summ) as "jjj", b.country
FROM(SELECT großhandelsfirma.name as…

Val.Val
- 61
- 5
0
votes
2 answers
SQL - Get the sum of several groups of records
DESIRED RESULT
Get the hours SUM of all [Hours] including only a single result from each [DevelopmentID] where [Revision] is highest value
e.g SUM 1, 2, 3, 5, 6 (Result should be 22.00)
I'm stuck trying to get the appropriate grouping.
DECLARE…

DreamTeK
- 32,537
- 27
- 112
- 171
0
votes
2 answers
Filter twice with MAX() in MySQL
I have the following table called my_values in a MySQL 5.7…

David
- 2,898
- 3
- 21
- 57