[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.2

Query problem

Asked by jung1975 in Oracle Database

Tags: month

I have a data like below:



ID      Test_Date      Lab      EPO      TX
111      10/1/2006            1100      
111      10/3/2006            1120      1
111      10/4/2006            1500      1
111      10/15/2006      28      1500      1
111      10/20/2006            1400      1
111      10/27/2006      30      1500      1
111      10/28/2006            1600      1
111      10/29/2006      40      1700      1
111      10/30/2006            1100      
111      11/1/2006            1200      1
111      11/3/2006            1100      1
111      11/6/2006      25      1300      1
111      11/7/2006            1700      1
111      11/8/2006      39.5      1200      1
111      11/9/2006                  1
111      11/10/2006            1800      
112      10/2/2006                  1
112      10/5/2006      32            
112      10/6/2006            1700      1
112      10/11/2006                  1
112      10/14/2006            2000      
112      10/24/2006      24            1
112      10/29/2006            2200      
112      11/4/2006                  
112      11/6/2006      42      3000      1
112      11/8/2006            2400      
112      11/11/2006            2400      1
112      11/20/2006            2300      
112      11/21/2006            1000      1
112      11/22/2006      35      1200      
112      11/24/2006            1500      1
112      11/26/2006      40      1700      
112      11/27/2006            1100      1
112      11/28/2006            1300      
112      11/29/2006            1400      1
112      11/30/2006            1100      1




What I am trying to do is grab the last lab value of previous month in each ID and if the lab value is > 39,
After that,
1) Review 5 days prior preceding and including the lab result date, and total the number of tx and amount of EPO. Do the calculation (EPO / TX).
In this case, PID 111 has 40 as the last lab value of the prior month, so we do our calculation (1700 + 1600 + 1500 +1400+ 1500 ) / 5 = 1540

2) Review proceeding 5 calendar days (excluding the lab result date), and total the number of tx and amount of EPO. Do the calculation ( EPO/Tx)
In this case, ( 1200 + 1100 + 1300 + 1700+1200) / 5 = 1300.

Here we do the comparison 1) and) 2) if 1) > 2) then we put N in the Y_N column, if 1) < 2) then Y, if 1) = 2) then E
In this case, 1) > 2), so we put N in the Y_N column




If the last lab value of previous month is < 39, then we go to the current month, in this case November, 2006 and look for Lab value > 39. If the lab value is less then 39 then just skip until you find a lab value > 39 in the same ID and then do our calculation like above.
In this case , we have 39.5 on 11/8/2006, so we do the same calculation.. five days back ( including the lab test date) and five days forward ( excluding the lab test date).

1) Five days back - (1200 + 1700 + 1300+1100+1200) / 5 = 1300
2) Five days forward – (1800) / 1 = 1800
In this case 1) is < 2), so we put Y in the Y_N column


And we move to the next ID and do the same calculation. In this case, the last lab value of prior month for ID=112 is < 39, so we are just going to go to the current month ( which is November , 2006) and do the calculation. In this case there is lab value > 39 on 11/6/2006, so we do 5 days back and 5 days forward calculation.

And there is also the lab test value 40 on 11/26/2006, so we do the 5 days back and 5 days forward calculation as well.

The desire output should look like:


ID      Test_Date      Lab      EPO      TX      Y_N
111      10/1/2006            1100            
111      10/3/2006            1120      1      
111      10/4/2006            1500      1      
111      10/15/2006      28      1500      1      
111      10/20/2006            1400      1      
111      10/27/2006      30      1500      1      
111      10/28/2006            1600      1      
111      10/29/2006      40      1700      1      N
111      10/30/2006            1100            
111      11/1/2006            1200      1      
111      11/3/2006            1100      1      
111      11/6/2006      25      1300      1      
111      11/7/2006            1700      1      
111      11/8/2006      39.5      1200      1      Y
111      11/9/2006                  1      
111      11/10/2006            1800            
112      10/2/2006                  1      
112      10/5/2006      32                  
112      10/6/2006            1700      1      
112      10/11/2006                  1      
112      10/14/2006            2000            
112      10/24/2006      24            1      
112      10/29/2006            2200            
112      11/4/2006                        
112      11/6/2006      42      3000      1      Y
112      11/8/2006            2400            
112      11/11/2006            2400      1      
112      11/20/2006            2300            
112      11/21/2006            1000      1      
112      11/22/2006      35      1200            
112      11/24/2006            1500      1      
112      11/26/2006      40      1700            N
112      11/27/2006            1100      1      
112      11/28/2006            1300            
112      11/29/2006            1400      1      
112      11/30/2006            1100      1      




to be able to create a sample data. Hereis the script:
CREATE TABLE [dbo].[lab](
[ID] [int] NULL,
[Test_Date] [datetime] NULL,
[Lab] [int] NULL,
[EPO] [int] NULL,
[TX] [int] NULL,
[Y_N] [nvarchar](1)
) ON [PRIMARY]


insert into lab (ID,Test_Date,Lab,EPO, TX) values(111,'20061001',null,1100,null)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(111,'20061003',null,1120,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(111,'20061004',null,1500,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(111,'20061015',28,1500,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(111,'20061020',null,1400,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(111,'20061027',30,1500,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(111,'20061028',null,1600,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(111,'20061029',40,1700,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(111,'20061030',null,1100,null)
insert into lab (ID,Test_Date,Lab,EPO, TX) values(111,'20061101',null,1200,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(111,'20061103',null,1100,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(111,'20061106',25,1300,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(111,'20061107',null,1700,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(111,'20061108',39.5,1200,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(111,'20061109',null,null,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(111,'20061110',null,1800,null)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(112,'20061002',null,null,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(112,'20061005',32,null,null)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(112,'20061006',null,1700,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(112,'20061011',null,null,1)
insert into lab (ID,Test_Date,Lab,EPO, TX) values(112,'20061014',null,2000,null)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(112,'20061024',24,null,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(112,'20061029',null,2200,null)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(112,'20061104',null,null,null)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(112,'20061106',42,3000,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(112,'20061108',null,2400,null)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(112,'20061111',null,2400,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(112,'20061120',null,2300,null)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(112,'20061121',null,1000,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(112,'20061122',35,1200,null)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(112,'20061124',null,1500,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(112,'20061126',40,1700,null)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(112,'20061127',null,1100,1)
insert into lab (ID,Test_Date,Lab,EPO, TX) values(112,'20061128',null,1300,null)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(112,'20061129',null,1400,1)

insert into lab (ID,Test_Date,Lab,EPO, TX) values(112,'20061130',null,1100,1)



[+][-]12/06/06 01:48 PM, ID: 18088751Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/06/06 01:53 PM, ID: 18088785Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/06/06 01:57 PM, ID: 18088828Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/06/06 02:00 PM, ID: 18088848Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/07/06 07:39 AM, ID: 18093918Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/07/06 07:43 AM, ID: 18093972Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/07/06 07:45 AM, ID: 18093987Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/07/06 08:07 AM, ID: 18094189Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/07/06 08:22 AM, ID: 18094358Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/07/06 08:40 AM, ID: 18094589Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/07/06 08:50 AM, ID: 18094706Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/07/06 08:59 AM, ID: 18094839Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/07/06 09:43 AM, ID: 18095230Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/07/06 09:51 AM, ID: 18095314Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/07/06 10:33 AM, ID: 18095714Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/07/06 10:55 AM, ID: 18095916Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/07/06 11:07 AM, ID: 18096004Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/07/06 03:12 PM, ID: 18098037Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/08/06 10:49 AM, ID: 18103585Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/08/06 10:54 AM, ID: 18103612Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Oracle Database
Tags: month
Sign Up Now!
Solution Provided By: paquicuba
Participating Experts: 2
Solution Grade: A
 
[+][-]12/08/06 02:06 PM, ID: 18105134Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/08/06 03:08 PM, ID: 18105518Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/11/06 08:41 PM, ID: 18120308Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/11/06 09:54 PM, ID: 18120526Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81