D
D
dqwe932017-09-27 12:07:32
MySQL
dqwe93, 2017-09-27 12:07:32

How does the MAX function work?

SELECT maker, MAX(type) 
FROM product 
GROUP BY maker 
HAVING COUNT(DISTINCT type) = 1 AND COUNT(model) > 1

The line where MAX(TYPE) is not clear in this code. The TYPE column contains the following values( PC, LAPTOP, Printer)
How does this function determine the maximum of these values?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Y, 2017-09-28
@x_shader

Since the query implies the output of groups in which there is only one type :
then MAX(type) in this case is a kind of "trick" to AND collapse into groups AND not group by two fields (maker, type).
With the same success, you can put MIN(type) there . the result will not change.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question