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 January 21st, 2009, 11:12 AM
Authorized User
 
Join Date: Dec 2005
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ramesh.kumarm
Default Looping with SQL // Very Urgent //

xxxxxx Jan Feb Mar
Orders 10 20 15
Ceased 2 4 3


This would be the input.

The output should resemble


xxxxxx Jan Feb Mar
Output 8 24 36


For every month the total number of orders are counted and subtracted from the ceased orders. Every successful month would hold the cumulative number of orders.
For instance for JAN > the output would be 10 – 2 = 8
But for FEB > (it has to be the output of JAN + the total number of FEB orders) – no. of ceased in FEB

Likewise – this has to be taken for the previous 13 months.
The output given here would be the output – if I run the sql script in APRIL.

Hope I’ve made myself clear.
We have to use only SQL statement to create this output.
[No usage of Procedures or PL/SQL]
The looping has to happen within SQL. Is there ANY way we can get this??

Thanks in advance for all your helps!

- Ramesh
__________________
Ramesh
\"Always Look For Something NEW\"

Last edited by ramesh.kumarm; January 21st, 2009 at 11:22 AM..
 
Old January 21st, 2009, 01:42 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Can you post the structure of the database? (we can assume that is month, orders, ceased)
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping through Array Values in T-SQL trufla SQL Server ASP 4 April 13th, 2007 06:14 AM
Looping through XML in SQL Server 2005 francislang SQL Server 2005 1 February 23rd, 2006 11:47 AM
Connection with SQL, URGENT PLEASE Amy_1 BOOK: Beginning ASP.NET 1.0 0 January 4th, 2006 02:16 PM
XSLT Looping Logic - Very Urgent ujayaraman XSLT 2 March 3rd, 2005 10:42 AM
Looping. Please help....Urgent junemo PHP How-To 0 July 20th, 2004 10:13 PM





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