Beginning SQL
Beginning SQL Beginning SQL
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
- Page 748: Chapter 13 Database Cache 354 In ad
- Page 752: Chapter 13 Again, the shotgun appro
- Page 756: Chapter 13 358 Figure 13-3 Leaf Ind
- Page 760: Chapter 13 Try It Out Dropping Inde
- Page 764: Chapter 13 64k Block 64k Block Figu
- Page 768: Chapter 13 ❑ Inner joins look lik
- Page 774: Chapter 1 Exercise 1 Solution A Exe
- Page 778: Chapter 2 Exercise 1 Solution There
- Page 782: Email, DateOfJoining ) VALUES ( 7,
- Page 786: Chapter 3 Exercise 1 Solution First
- Page 790: As well as joining the tables, you
- Page 794: Figure A-2 Notice that Table1 is re
- Page 800: Appendix A 380 You might receive sl
- Page 804: Appendix A 382 You should use the f
- Page 808: Appendix A Your answer may differ,
- Page 812: Appendix A WHERE (SELECT COUNT(*) f
- Page 816: Appendix A Exercise 2 Solution CREA
- Page 820: Appendix A Chapter 13 Exercise 1 So
- Page 824: Appendix B 392 Click the database i
- Page 828: Appendix B 394 Click Install to beg
- Page 832: Appendix B 396 Select the Detailed
- Page 836: Appendix B 398 Leave it at the defa
- Page 840: Appendix B 400 Having entered your
- Page 844: Appendix B 402 Figure B-20 The inst
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