Beginning SQL

Beginning SQL Beginning SQL

marjan.fesb.hr
from marjan.fesb.hr More from this publisher
20.07.2013 Views

Executing the query provides the following results on SQL Server; you may get slightly different ones with DB2 or Oracle: MemberId FirstName LastName 6 Jenny Jones 5 John Jones 8 Jack Johnson 7 John Jackson Because the chairwoman knows she spoke to a woman, she could deduce that she’s looking for Jenny Jones. Keeping track of gender in the MemberDetails table would make getting these results even easier. How should you decide a good value for the results returned by the DIFFERENCE() function? It’s a matter of guesswork based on how many results are returned and whether those results are likely to contain the one result you want. Any value 3 or higher has a strong possibility of being a close match, and you can usually rule out anything below that. Chapter 6 Exercise 1 Solution The first part of the question’s answer is as follows: SELECT Category, COUNT(DVDPrice), SUM(DVDPrice * 1.1) FROM Films INNER JOIN Category ON Films.CategoryId = Category.CategoryId WHERE AvailableOnDVD = ‘Y’ GROUP BY Category; The preceding SQL provides the following results: Category COUNT(DVDPrice), SUM(DVDPrice * 1.1) Historical 3 38.423 Horror 2 20.834 Romance 1 14.289 Sci-fi 1 14.289 Thriller 2 17.578 War 1 14.289 Exercise Answers 379

Executing the query provides the following results on <strong>SQL</strong> Server; you may get slightly different ones<br />

with DB2 or Oracle:<br />

MemberId FirstName LastName<br />

6 Jenny Jones<br />

5 John Jones<br />

8 Jack Johnson<br />

7 John Jackson<br />

Because the chairwoman knows she spoke to a woman, she could deduce that she’s looking for Jenny<br />

Jones. Keeping track of gender in the MemberDetails table would make getting these results even easier.<br />

How should you decide a good value for the results returned by the DIFFERENCE() function? It’s a matter<br />

of guesswork based on how many results are returned and whether those results are likely to contain<br />

the one result you want. Any value 3 or higher has a strong possibility of being a close match, and you<br />

can usually rule out anything below that.<br />

Chapter 6<br />

Exercise 1 Solution<br />

The first part of the question’s answer is as follows:<br />

SELECT Category, COUNT(DVDPrice), SUM(DVDPrice * 1.1)<br />

FROM Films<br />

INNER JOIN Category<br />

ON Films.CategoryId = Category.CategoryId<br />

WHERE AvailableOnDVD = ‘Y’<br />

GROUP BY Category;<br />

The preceding <strong>SQL</strong> provides the following results:<br />

Category COUNT(DVDPrice), SUM(DVDPrice * 1.1)<br />

Historical 3 38.423<br />

Horror 2 20.834<br />

Romance 1 14.289<br />

Sci-fi 1 14.289<br />

Thriller 2 17.578<br />

War 1 14.289<br />

Exercise Answers<br />

379

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!