Questions tagged [max]

Finding the maximum value in a group of items

67 questions
18
votes
4 answers

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 |Bronze | |A |200 |Silver | |A |300 …
Lambo Jayapalan
  • 367
  • 2
  • 4
  • 8
16
votes
2 answers

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 length of the data entered + 2 bytes. Please help…
Peter PitLock
  • 1,405
  • 4
  • 24
  • 32
9
votes
3 answers

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 matches the given name and argument types. You…
xehpuk
  • 327
  • 2
  • 5
  • 11
5
votes
1 answer

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 of 56 bytes A secondary index is defined on a…
Revolucion for Monica
  • 677
  • 2
  • 11
  • 27
5
votes
2 answers

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"}, {"$unwind": "$rounds.matches"}, {"$project": …
Fierce82
  • 183
  • 1
  • 1
  • 6
4
votes
2 answers

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 mytable ([ID] int, [TEMP] FLOAT, [DATE]…
Mr. Geologist
  • 55
  • 1
  • 2
  • 8
4
votes
5 answers

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 | 1293 | | 1 | BILL | Y | 10-Oct …
heye
  • 129
  • 3
  • 5
  • 14
4
votes
2 answers

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 fast (0,04 sec): SELECT MAX(Snapshot_Nummer) FROM…
matt
  • 143
  • 5
4
votes
2 answers

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 function MAX, but I'm not getting anywhere. I'm…
Emperor1951
  • 43
  • 1
  • 1
  • 4
2
votes
2 answers

Ignore duplicate rows in a join - and take only one of them

In MySQL I have tables, simplified as follows: companies (id, name, rank, trade_sector_id) orders (id, company_id, paid, subtotal) trade_sectors (id, label) companies_notes (id, company_id, notes) I want a single row for each company…
Ade
  • 123
  • 6
2
votes
2 answers

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 temperature and bloodPressure data collected at different…
KAE
  • 143
  • 1
  • 7
2
votes
1 answer

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 USD RET RET ACC ACC …
rainman
  • 205
  • 1
  • 4
  • 13
2
votes
2 answers

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 requirement: Index cardCode updateDate …
2
votes
1 answer

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 | Message | SentOn I use a while statement to…
Mars
  • 65
  • 5
2
votes
1 answer

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 actually have only 24 nodes to store data? If the data…
Babu James
  • 121
  • 3
1
2 3 4 5