Chapter 9 Application Flashcards

1
Q

Sort by the car column.

A

Select * from NASCAR2 order by car;

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

Sort by the car column explicitly cast as an integer.

A

Select * from NASCAR2 order by cast(car as signed);

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

Sort by the car column implicitly cast as an integer.

A

Select * from NASCAR2 order by car + 0;

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

Sort by the car column after it has been padded with leading zeros.

A

Select LPAD(car, 2, ‘0’) as car, driver from NASCAR2 order by car;

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

Apply the LOCATE function to find the blank character in the driver string.

A

Select driver, LOCATE(‘ ‘, driver) as space from NASCAR2;

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

Use SUBSTRING() in combination with LOCATE() to parse driver into first and last names.

A

Select driver, substring(driver, 1, LOCATE(‘ ‘,driver) - 1) as FirstName, Substring(driver, Locate(‘ ‘, driver)+1) as LastName from NASCAR2;

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

Invoke SUBSTRING_INDEX() to parse driver into first and last names.

A

Select SUBSTRING_INDEX(driver,’ ‘, 1) as FirstName, SUBSTRING_INDEX(driver,’ ‘, -1) as LastName from NASCAR2;

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

Prepare a query that projects car, amount, and integer values for amount returned by ROUND(), TRUNCATE(), FLOOR(), and CEILING(). Show the result set for cars 2 and 8.

A

Select Round(amount,0) as Rounded_Amount, Truncate(amount,0) as Truncated_Amount, Floor(amount) as RoundedDown_Amount, Ceiling(amount) as RoundedUp_Amount from NASCAR2 where car=08 or car=02;

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

Query NASCAR to projects all columns for those rows with amount values BETWEEN four and five thousand (dollars).

A

select * from NASCAR2 where amount BETWEEN 4000 and 5000;

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

Code a query that invokes NOW(), SYSDATE(), and CURDATE(). Show the result set given that this query is issued during the exam 2 period.

A

select now(), sysdate(), curdate();

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

Given a date type named lastRaceDate is added to NASCAR, prepare a query that projects driver and the three numeric values for month, day and year, and separated by forward slashes (e.g. 02/28/2015). Use CONCAT(), MONTH(), DAYOFWEEK(), and YEAR() in the SELECT clause.

A

Select concat(driver,’ ‘,lastRaceDate), Month(lastRaceDate) as Month, DayofWeek(lastRaceDate) as Day, Year(lastRaceDate) as Year from NASCAR2;

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