 |
|
 |
|
Next: Need some guidence as to how display Market Baske..
|
| Author |
Message |
External

Since: Jan 22, 2008 Posts: 2
|
(Msg. 1) Posted: Fri Oct 09, 2009 7:39 pm
Post subject: help on sql Archived from groups: comp>databases>oracle>server, others (more info?)
|
|
|
Hi sql gurus,
I need some help and also curious on how to write this in single sql
statement, requirements goes like this
Table structure
================
create table find_fixed_open (
find number,
fixed number,
open number,
bug_when date
);
Data
=============
insert into find_fixed_open values(5,3,2,'10/01/2009');
insert into find_fixed_open values(52,38,16,'10/02/2009');
insert into find_fixed_open values(68,45,39,'10/03/2009');
insert into find_fixed_open values(112,59,92,'10/04/2009');
insert into find_fixed_open values(45,12,125,'10/05/2009');
Formula
=========
Open = Find - fixed + previous rows open(basically open is cumulative)
i.e.
5 - 3 + 0 = 2
52 - 38 + 2 = 16
68 - 45 + 16 = 39
112 - 59 + 39 = 92
45 - 12 + 92 = 125
Please help me and enlighten me.
Thank you
Raju >> Stay informed about: help on sql |
|
| Back to top |
|
 |  |
External

Since: Jan 02, 2008 Posts: 152
|
(Msg. 2) Posted: Fri Oct 09, 2009 8:29 pm
Post subject: Re: help on sql [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Oct 9, 10:39 pm, RA wrote:
> Hi sql gurus,
>
> I need some help and also curious on how to write this in single sql
> statement, requirements goes like this
>
> Table structure
> ================
> create table find_fixed_open (
> find number,
> fixed number,
> open number,
> bug_when date
> );
>
> Data
> =============
> insert into find_fixed_open values(5,3,2,'10/01/2009');
> insert into find_fixed_open values(52,38,16,'10/02/2009');
> insert into find_fixed_open values(68,45,39,'10/03/2009');
> insert into find_fixed_open values(112,59,92,'10/04/2009');
> insert into find_fixed_open values(45,12,125,'10/05/2009');
>
> Formula
> =========
> Open = Find - fixed + previous rows open(basically open is cumulative)
> i.e.
> 5 - 3 + 0 = 2
> 52 - 38 + 2 = 16
> 68 - 45 + 16 = 39
> 112 - 59 + 39 = 92
> 45 - 12 + 92 = 125
So is this the result you want:
2
16
39
92
125
??????
or a single summand, as in
294
??????????
(Hint to other posters: clear descriptions of your problem go a long
way to getting help)
>
> Please help me and enlighten me.
>
> Thank you
> Raju
Aside from OPEN being a keyword,
Break the problem down into steps.
The individual counts can be obtained using
SELECT (find-fixed+open) opencount from find_fixed_open;
Assuming you wanted the individual counts, you can stop here.
That basically gives you a table of the individual counts. Now given
that table, how would you compute the sum? Here's a hint:
SELECT SUM(opencount) ...
Assuming you want the single summation, can you finish the work by
putting these hints together into one statement?
HTH,
Ed >> Stay informed about: help on sql |
|
| Back to top |
|
 |  |
External

Since: Oct 09, 2009 Posts: 3
|
(Msg. 3) Posted: Fri Oct 09, 2009 11:41 pm
Post subject: Re: help on sql [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Sorry for the messup
Sample Data
=============
insert into find_fixed_open values(5,3,2,'10/01/2009');
insert into find_fixed_open values(52,38,14,'10/02/2009');
insert into find_fixed_open values(68,45,23,'10/03/2009');
insert into find_fixed_open values(112,59,53,'10/04/2009');
insert into find_fixed_open values(45,12,33,'10/05/2009');
Output should look like this
===================
'10/01/2009',5,3,2
'10/02/2009',52,38,16
'10/03/2009',68,45,39
'10/04/2009',112,59,92
'10/05/2009',45,12,125
thanks
Raju >> Stay informed about: help on sql |
|
| Back to top |
|
 |  |
External

Since: Oct 09, 2009 Posts: 3
|
(Msg. 4) Posted: Fri Oct 09, 2009 11:45 pm
Post subject: Re: help on sql [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Oct 09, 2009 Posts: 3
|
(Msg. 5) Posted: Sat Oct 10, 2009 12:00 am
Post subject: Re: help on sql [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Dec 10, 2003 Posts: 57
|
(Msg. 6) Posted: Sat Oct 10, 2009 3:25 am
Post subject: Re: help on sql [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
"RA" a écrit dans le message de db579098-d4b0-4778-8f65-3cff8e43d9a2.TakeThisOut@f20g2000prn.googlegroups.com...
| Hi sql gurus,
|
| I need some help and also curious on how to write this in single sql
| statement, requirements goes like this
|
| Table structure
| ================
| create table find_fixed_open (
| find number,
| fixed number,
| open number,
| bug_when date
| );
|
|
| Data
| =============
| insert into find_fixed_open values(5,3,2,'10/01/2009');
| insert into find_fixed_open values(52,38,16,'10/02/2009');
| insert into find_fixed_open values(68,45,39,'10/03/2009');
| insert into find_fixed_open values(112,59,92,'10/04/2009');
| insert into find_fixed_open values(45,12,125,'10/05/2009');
|
|
| Formula
| =========
| Open = Find - fixed + previous rows open(basically open is cumulative)
| i.e.
| 5 - 3 + 0 = 2
| 52 - 38 + 2 = 16
| 68 - 45 + 16 = 39
| 112 - 59 + 39 = 92
| 45 - 12 + 92 = 125
|
| Please help me and enlighten me.
|
| Thank you
| Raju
SQL> select bug_when, find, fixed, open,
2 sum(find-fixed) over (order by bug_when) computed_open
3 from find_fixed_open
4 order by bug_when
5 /
BUG_WHEN FIND FIXED OPEN COMPUTED_OPEN
---------- ---------- ---------- ---------- -------------
10/01/2009 5 3 2 2
10/02/2009 52 38 16 16
10/03/2009 68 45 39 39
10/04/2009 112 59 92 92
10/05/2009 45 12 125 125
5 rows selected.
Regards
Michel >> Stay informed about: help on sql |
|
| Back to top |
|
 |  |
External

Since: Dec 24, 2007 Posts: 211
|
(Msg. 7) Posted: Wed Nov 18, 2009 10:25 am
Post subject: Re: help on sql [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
RA wrote:
> Hi sql gurus,
>
> I need some help and also curious on how to write this in single sql
> statement, requirements goes like this
>
> Table structure
> ================
> create table find_fixed_open (
> find number,
> fixed number,
> open number,
> bug_when date
> );
>
>
> Data
> =============
> insert into find_fixed_open values(5,3,2,'10/01/2009');
>-------------------------------------------^^^^^^^^^^
Aaaargghhhh! That NOT a date - it's a string! I read it
as ten divided by one, divided by twothousandandnine
Promise to never, ever do that again! Typecast your
data! You should have use the to_date function here!
--
Regards,
Frank van Bortel >> Stay informed about: help on sql |
|
| Back to top |
|
 |  |
| Related Topics: | Replacing a subselect with Collections - Hi all oracle users, I have a cursor which fetches a few thousand records. Inside it I have a subselect which is used for decoding one field. CURSOR snap_crs IS SELECT decode (snap.id, 1, (select code_ptr from anag_ptr where desc_ptr =..
how to refresh a sequence - How could I refresh a sequence in Oracle using an SQL statement? I've got the problem, that the current number of a sequence is less the highest index in a table, where I want to use the sequence. Regards, Robert
Using NonUnique Index to Enforce Uniqueness - Oracle manual describes using non unique index to enforce unique constraint so that the index will not be dropped with constraint is diabled. But I dont understand why non unique index can enforce uniqueness?
Triggers and Window Service - Hi, Is there a way to create an oracle Trigger that will start a window service? I am trying to get the service away from running a timer. Running Oracle 9i and windows 2K or XP Thanks
aggregation over two hierarchies - In my application there are two given tables: JOB table: job_id open closed splitfrom mergedto ================================================= AAAA 1/1/90 1/1/00 BBBB 1/1/80 1/1/00 CCCC 1/1/00 1/1/01 AAAA .. |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|