Wrox Programmer Forums
|
BOOK: Beginning SQL Server 2005 Programming ISBN: 978-0-7645-8433-6
This is the forum to discuss the Wrox book Beginning SQL Server 2005 Programming by Robert Vieira; ISBN: 9780764584336
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning SQL Server 2005 Programming ISBN: 978-0-7645-8433-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 24th, 2007, 05:22 PM
Authorized User
 
Join Date: Dec 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default Beg. SQL Programming Chapter 7 Exercise Quest 3

Here's the exercise problem from Chapter 7, exercise 3 (for the Northwind database):

Show the five most recent orders that were purchased from a customer who has spent more
than $25,000 with Northwind.


The T-SQL Answer provided in the book (shown below), doesn't show the order information, only the CustomerID. How can I show the Order Number as well? If I simply add "o.OrderID" to the subquery, I get the following error:

Msg 8120, Level 16, State 1, Line 1
Column 'Orders.OrderID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Msg 116, Level 16, State 1, Line 1
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.


Here is the T-SQL answer as provided in the book:

SELECT TOP 5 *
FROM Orders oo
WHERE CustomerID IN
(
SELECT c.CustomerID
FROM Customers c
JOIN Orders o
ON c.CustomerID = o.CustomerID
JOIN [Order Details] od
ON o.OrderID = od.OrderID
GROUP BY c.CustomerID
HAVING SUM(UnitPrice * (1-Discount) * Quantity) > 25000
)
ORDER BY OrderDate


Sincerely,
Brian
__________________
Sincerely,
Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 5 Exercise 2 diango BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 4 February 1st, 2011 03:24 PM
chapter 3 exercise 4 walkamongus BOOK: Beginning JavaScript 3rd Ed. ISBN: 978-0-470-05151-1 0 September 10th, 2007 09:34 PM
Problem with Exercise in Beg. asp.net for VB.net! mrfella71 BOOK: Beginning ASP.NET 1.0 1 October 23rd, 2005 12:06 PM
Chapter 5 and 6 of Beg. VB.Net 2003 Koga BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 1 October 9th, 2004 05:02 AM
Chapter 4, Exercise 3 DRAYKKO BOOK: Beginning Java 2 3 July 9th, 2004 02:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.