Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old October 7th, 2008, 07:45 PM
annecarterfredi@gmail.com
Guest
 
Posts: n/a
Default SQL help

I have a resultset like this:

DATE NUMBER_OF_TASKS_CLOSED NUMBER_OF_TASKS_CREATED
PENDING_TASKS
----------
----------------------
----------------------- -------------
10/31/2007 1591
1723 132
11/01/2007 1821
4511 2690
11/02/2007 2465
5530 3065
11/03/2007 1028
1916 888
11/04/2007
1
1 0


PENDING_TASKS should be calculated as (NUMBER_OF_TASKS_CREATED -
NUMBER_OF_TASKS_CLOSED + PENDING_TASKS from Previous day).

While I can calculate NUMBER_OF_TASKS_CREATED -
NUMBER_OF_TASKS_CLOSED easily(which is shown in the resultset above),
I don't know how to add " PENDING_TASKS from Previous day". Pls help.

Thanks.
  #2  
Old October 7th, 2008, 07:45 PM
annecarterfredi@gmail.com
Guest
 
Posts: n/a
Default Re: SQL help

DATE NUMBER_OF_TASKS_CLOSED NUMBER_OF_TASKS_CREATED PENDING_TASKS
---------- ---------------------- -----------------------
-------------
10/31/2007 1591 1723
132
11/01/2007 1821 4511
2690
11/02/2007 2465 5530
3065
11/03/2007 1028 1916
888
11/04/2007 1 1
0

On Oct 7, 2:36*pm, "annecarterfr...@gmail.com"
<annecarterfr...@gmail.comwrote:
Quote:
I have a resultset like this:
>
DATE * * * * NUMBER_OF_TASKS_CLOSED * * NUMBER_OF_TASKS_CREATED
PENDING_TASKS
----------
----------------------
----------------------- * * * * * * * * * * * * * * * * -------------
10/31/2007 * * * * * * * * * 1591
1723 * * * * * * * * * * * * * * * * * * * * * 132
11/01/2007 * * * * * * * * * 1821
4511 * * * * * * * * * * * * * * * * * * * * * 2690
11/02/2007 * * * * * * * * * 2465
5530 * * * * * * * * * * * * * * * * * * * * * 3065
11/03/2007 * * * * * * * * * 1028
1916 * * * * * * * * * * * * * * * * * * * * * 888
11/04/2007
1
1 * * * * * * * * * * * * * * * * * ** * * * * * 0
>
PENDING_TASKS should be calculated as (NUMBER_OF_TASKS_CREATED -
NUMBER_OF_TASKS_CLOSED + PENDING_TASKS from Previous day).
>
While *I can calculate NUMBER_OF_TASKS_CREATED -
NUMBER_OF_TASKS_CLOSED easily(which is shown in the resultset above),
I don't know how to add " PENDING_TASKS from Previous day". Pls help.
>
Thanks.
  #3  
Old October 8th, 2008, 05:15 AM
Lennart
Guest
 
Posts: n/a
Default Re: SQL help

On 7 Okt, 20:36, "annecarterfr...@gmail.com"
<annecarterfr...@gmail.comwrote:
Quote:
I have a resultset like this:
>
DATE * * * * NUMBER_OF_TASKS_CLOSED * * NUMBER_OF_TASKS_CREATED
PENDING_TASKS
----------
----------------------
----------------------- * * * * * * * * * * * * * * * * -------------
10/31/2007 * * * * * * * * * 1591
1723 * * * * * * * * * * * * * * * * * * * * * 132
11/01/2007 * * * * * * * * * 1821
4511 * * * * * * * * * * * * * * * * * * * * * 2690
11/02/2007 * * * * * * * * * 2465
5530 * * * * * * * * * * * * * * * * * * * * * 3065
11/03/2007 * * * * * * * * * 1028
1916 * * * * * * * * * * * * * * * * * * * * * 888
11/04/2007
1
1 * * * * * * * * * * * * * * * * * ** * * * * * 0
>
PENDING_TASKS should be calculated as (NUMBER_OF_TASKS_CREATED -
NUMBER_OF_TASKS_CLOSED + PENDING_TASKS from Previous day).
>
While *I can calculate NUMBER_OF_TASKS_CREATED -
NUMBER_OF_TASKS_CLOSED easily(which is shown in the resultset above),
I don't know how to add " PENDING_TASKS from Previous day". Pls help.
>
Thanks.
Assuming your current query looks like (it is often a good idea to
post ddl + what you have achieved so far :-)

select DATE,
sum(x) as NUMBER_OF_TASKS_CLOSED,
sum(y) as NUMBER_OF_TASKS_CREATED,
(select sum(z) from T T2 where T2.date = T1.DATE - 1 day)
as PENDING_TASKS
from T T1 group by DATE

HTH
/Lennart
  #4  
Old October 8th, 2008, 05:45 PM
--CELKO--
Guest
 
Posts: n/a
Default Re: SQL help

"A problem well stated is a problem half solved." -- Charles F.
Kettering

Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in
your schema are. If you know how, follow ISO-11179 data element naming
conventions and formatting rules. Temporal data should use ISO-8601
formats. Code should be in Standard SQL as much as possible and not
local dialect.

Sample data is also a good idea, along with clear specifications. It
is very hard to debug code when you do not let us see it. If you want
to learn how to ask a question on a Newsgroup, look at:
http://www.catb.org/~esr/faqs/smart-questions.html

  #5  
Old October 8th, 2008, 06:25 PM
annecarterfredi@gmail.com
Guest
 
Posts: n/a
Default Re: SQL help

Thanks for your reply. I have found the solution after some research.
It's similar to Lennart's solution.

On Oct 8, 12:37*pm, --CELKO-- <jcelko...@earthlink.netwrote:
Quote:
"A problem well stated is a problem half solved." -- Charles F.
Kettering
>
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in
your schema are. If you know how, follow ISO-11179 data element naming
conventions and formatting rules. *Temporal data should use ISO-8601
formats. *Code should be in Standard SQL as much as possible and not
local dialect.
>
Sample data is also a good idea, along with clear specifications. *It
is very hard to debug code when you do not let us see it. If you want
to learn how to ask a question on a Newsgroup, look at:http://www.catb.org/~esr/faqs/smart-questions.html
 

Bookmarks

Thread Tools

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles