Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language 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 December 19th, 2004, 10:51 AM
Authorized User
 
Join Date: Oct 2004
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default What is the Query for this

hi,

Item Table:
Item Id Item Name
I1 Pencil
I2 Eraser
I3 Pen

Order Item Table:
Order Id Item Id Quantity
O1 I1 20
O2 I1 25
O3 I2 10
O4 I1 10
O5 I3 15

Question is: Query to get Itemwise total quanity.


A.D.Ramkumar
__________________
Ramkumar A D
 
Old December 19th, 2004, 02:41 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

You can try this

Code:
SELECT     OrderID,ItemID, SUM(Quantity) AS Total_Quantity
FROM         dbo.[Order Details]
GROUP BY OrderID


Jaime E. Maccou
 
Old December 19th, 2004, 03:14 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

Itemwise:
GROUP BY ItemId

 
Old December 19th, 2004, 04:28 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

SELECT tbItem.ItemId, ItemName, SUM(Quantity) AS Quantity
FROM tbItem INNER JOIN tbOrderItem
ON tbItem.ItemId = tbOrderItem.ItemId
GROUP BY tbItem.ItemId, tbItem.ItemName







Similar Threads
Thread Thread Starter Forum Replies Last Post
Output Query to txt file from SQL Query everest SQL Server 2005 4 November 22nd, 2007 01:49 AM
how to make a query from an existing query raport SQL Language 3 November 13th, 2006 08:59 PM
I solved insert query.now see this Update Query. [email protected] VB.NET 2002/2003 Basics 2 September 21st, 2006 12:48 AM
Syntax error in query. Incomplete query clause. dispickle ADO.NET 3 April 16th, 2004 01:04 PM
Error on Make-Table Query In Union Query rylemer Access 1 August 20th, 2003 07:42 PM





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