"min()" with two parameters

Asked

Viewed 114 times

0

The person who worked before me at the company made that code:

MIN(DATEPART('weekday',[Entrega Data Real]),6)

What this 6 means?

A min() can have two parameters?

  • 1

    Which SQL are you using ? MYSQL? SQL server? Oracle?

  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).

1 answer

2

No, we have no way of knowing what it means, but by code the result should be a maximum of 6, i.e., if the day of the week is 7 (probably Sunday, depends on the culture used) then it will consider 6 (probably Saturday), but if any days are below 7, he will consider the day of the delivery week.

A function min() it must have at least two arguments since it results in a minimum value between two or more of them. If he had only one argument the result would always be himself.

Note that in this case it is not being used as an aggregation but rather a simple expression, it just takes the value of a column in a row and compares it with the literal 6. This is done row by row, but it is not looking for the minimum of all lines, as you probably think. It only works to aggregate if there are any clauses in query has something to group everything. Nothing posted indicates this and even if it is used so the form of the written function would not make the aggregation correctly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.