Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > BOOK: Beginning SQL Server 2005 Programming ISBN: 978-0-7645-8433-6
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 24th, 2007, 04:22 PM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 34
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 02: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



All times are GMT -4. The time now is 12:26 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.