Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Oracle SQL Query

Posted on 2013-10-31
2
Medium Priority
?
342 Views
Last Modified: 2013-10-31
Hi Experts,

I have the table with below columns
1.      ID
2.      WORK_ID
3.      VOLUME


It has a composite primary key ID and W_ID
Below is the data

ID       W_ID      VOL
1      1      10
2      2      10
3      2      10
3      3      10
1      4      15
3      5      10

Output : I want the ID and volume as out put, but calculating volume has some rules

1.      If Works is shared between ID’s, volume should be equally divided between them.

Sample out put depending on above table is

1 – 10 + 15 = 25
2 – 10/2 = 5 (Work 2 shared by both 2 and 3)
3 – 10/2 + 10 + 10 = 25

I need a query to get the above result.

 
Thanks,
Ravi
0
Comment
2 Comments
 
LVL 41

Accepted Solution

by:
Sharath earned 2000 total points
ID: 39615995
try this.
select ID,SUM(VOL) VOL
  from (
select t1.ID,t1.W_ID,t1.VOL/t2.cnt VOL
  from test t1 
  join (select W_ID,COUNT(W_ID) cnt from test group by W_ID) t2
    on t1.W_ID = t2.W_ID) t3
 group by ID

Open in new window


http://sqlfiddle.com/#!4/8ceed/12
0
 

Author Closing Comment

by:Ravi Kiran Reddy Katkuri
ID: 39616059
Awsome, thanks a lot for the help.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question