Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could someone please explain OVER

I have borrowed a query and adapted it for my own purposes, but I don't like doing this when I am not entirely sure what it is doing. SQL docs are less than descriptive on this clause. Here is what I borrowed and modified, can you tell me what it is doing basically?

(SELECT Id FROM
    (
        SELECT 
            Id
            ,RANK() OVER ( PARTITION BY DropStatusId ORDER BY StatusDate DESC) [Rank] 
        FROM 
            [dbo].[tblLHTrackingHistory] [TempHistory]
        WHERE 
            [TempHistory].[DropStatusId] = [DropStatus].[Id]
    ) [TT1] WHERE [Rank] = 1
)
like image 575
joshlrogers Avatar asked Feb 19 '10 18:02

joshlrogers


People also ask

Can you please explain or could you please explain?

Always use "could" if you are asking for a favour. Can is generally used to comment on the capability of a person to perform a task. So, when you ask "Can you explain it to me?", you are basically asking whether the opposite person is capable of explaining something.

Can or could you explain?

'Can' refers to a general truth or something that has a strong sense of possibility. 'Could' refers to something that has a weak possibility, or something that might happen, but is not necessarily a general truth.

Is it rude to say could you please?

Should a question start with "can you please" or "could you please"? If both are correct, what is the difference between them? Answer: Both are technically correct, but the "Could you" form is polite (and preferable), while the "Can you" is almost an implied command that leaves no choice to the doer.

When to say could you please?

We also use 'could' to ask permission; it is more polite or formal than 'can'. Changing the word order to "could you please" is no more or less polite - it's a matter of style. whether requests starting with "Please can/could you..." render the same degree of politeness as those that start with "Could you please...".


1 Answers

The OVER clause means you're using analytics (vs say aggregates). Per the OVER documentation:

Determines the partitioning and ordering of the rowset before the associated window function is applied.

Unlike aggregates, analytics don't require a GROUP BY to be defined.

like image 132
OMG Ponies Avatar answered Sep 18 '22 11:09

OMG Ponies