Sql: what does Max () -1 mean?

I have some questions regarding Max ()

  • What does the following query mean?

    SELECT MAX(X) -1 FROM T

  • I found out that the syntax should be: SELECT (MAX(X) -1) as max_minus_one FROM T no?

  • Max()Should the aggregation function (i.e. ) be followed GRUOP BY?

+3
source share
4 answers

MAX(x) - 1 just means the maximum x value in the table minus one.

You can always use parentheses and aliases ( as some_cool_name) to make the object more understandable or to change the names as a result. But the first syntax is perfectly correct.

You will need GROUP BY GROUP BYit if you intend to choose something larger that the aggregated value, for example, is:

select
    userName,
    avg(age)
from
    users
group by
    userName
+4
source

SELECT MAX (X) -1

and

SELECT (MAX (X) -1)

match up.

GROUP BY, .

+2

This means that "one is less than the maximum value in column X". (a) No, this adds some things. (b) No, not when you select one column like this.

+1
source

and. It imposes a maximum value and subtracts 1.

B. If it is only an agregate function, then no. If you specify another column, you should use it in GROUP BY.

+1
source

All Articles