Example Queries Flashcards

1
Q

Example of average function.

A

SELECT AVG(column_name) FROM table_name

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

Example of above average statement.

A

SELECT ProductName, Price FROM Products

WHERE Price>(SELECT AVG(Price) FROM Products);

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

Statement that gets count

A

SELECT COUNT(column_name) FROM table_name;

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

Example of returns distinct value.

A

SELECT COUNT(DISTINCT column_name) FROM table_name;

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

The following SQL statement counts the number of orders from “CustomerID”=7 from the “Orders” table:

A
SELECT COUNT(CustomerID) AS OrdersFromCustomerID7 FROM Orders
WHERE CustomerID=7;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The FIRST() function returns the first value of the selected column.

A

SELECT FIRST(column_name) FROM table_name;

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

SQL LAST() Syntax

A

SELECT LAST(column_name) FROM table_name;

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

SQL MAX() Syntax

A

SELECT MAX(column_name) FROM table_name;

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

SQL MIN() Syntax

A

SELECT MIN(column_name) FROM table_name;

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

SQL MIN() Syntax

A

SELECT MIN(column_name) FROM table_name;

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

SQL SUM() Syntax

SELECT SUM(column_name

A

SELECT SUM(column_name) FROM table_name;

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

SQL GROUP BY Syntax

A

SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name;

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

The following SQL statement counts as orders grouped by shippers:

A

SELECT Shippers.ShipperName,COUNT(Orders.OrderID) AS NumberOfOrders FROM Orders
LEFT JOIN Shippers
ON Orders.ShipperID=Shippers.ShipperID
GROUP BY ShipperName;

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

The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions.

A

SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value;

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

The UCASE() function converts the value of a field to uppercase.

A

SELECT UCASE(column_name) FROM table_name;

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

The following SQL statement selects the “CustomerName” and “City” columns from the “Customers” table, and converts the “CustomerName” column to uppercase:

A
SELECT UCASE(CustomerName) AS Customer, City
FROM Customers;
17
Q

The LCASE() function converts the value of a field to lowercase.

A

SELECT LCASE(column_name) FROM table_name;

18
Q

The following SQL statement selects the “CustomerName” and “City” columns from the “Customers” table, and converts the “CustomerName” column to lowercase:

A
SELECT LCASE(CustomerName) AS Customer, City
FROM Customers;
19
Q

The MID() function is used to extract characters from a text field.

A

SELECT MID(column_name,start,length) ASsome_nameFROM table_name;

20
Q

The following SQL statement selects the first four characters from the “City” column from the “Customers” table:

A
SELECT MID(City,1,4) AS ShortCity
FROM Customers;
21
Q

The LEN() function returns the length of the value in a text field.

A

SELECT LEN(column_name) FROM table_name;

22
Q

The FORMAT() function is used to format how a field is to be displayed.

A

SELECT FORMAT(column_name,format) FROM table_name;

23
Q

The following SQL statement selects the product name, and price for today (formatted like YYYY-MM-DD) from the “Products” table:

A

SELECT ProductName, Price, FORMAT(Now(),’YYYY-MM-DD’) AS PerDate
FROM Products;