Queries - Intermidiate functions Flashcards

1
Q

What is a nested Query?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why use a nested Query?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to use a nested Query

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is an Aggregator and where to use is?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Example of aggregators

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

ORDER BY()

A

ORDER BY() allows the sorting of the tuples resulting from the SELECT() command in a defined order. Aliases can be used in the ORDER BY() clause.
E.g.
SELECT ProductCat AS Category, ProductName
FROM Product
ORDER BY Category ASC, Price DESC;

The above will return the ProductCat and the ProductName (from the Product table) ordered the ascending order for the ProductCat column and descending for the ProductName column.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

TOP()

A

TOP() is not ANSI! TOP returns a given number of rows, either as a positive integer or as a percentage of all qualifying rows. The number of rows can be specified as a constant or as an expression. Requires an ORDER BY in order to make sense:
E.g.
SELECT TOP 10 Name, ListPrice
FROM Production.Product
ORDER BY ListPrice DESC;
The above returns the 10 most expensive (10 top ListPrice ind descending order) products together with the name of the product.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

WITH TIES

A

To be used together with “TOP” - WITH TIES returns all tuples qualifying for the “TOP” clause. NB! - How to use the function is not very clear…
E.g:
SELECT TOP 10 WITH TIES Name, ListPrice
FROM Production.Product
ORDER BY ListPrice DESC

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

PERCENT

A

To be used together with TOP - Returns a percentage of the eligible rows instead of fixed number.
E.g.
SELECT TOP 10 PERCENT Name, ListPrice
FROM SalesLT.Product
ORDER BY ListPrice DESC;
Can also be used together with “WITH TIES”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly