Help !!! - partition by clause
hi. i have the following table
table : item_tracker
date | item_code | begin_price
end of each day, one record for each item is getting written to this table. now after the records are written, i want to calculate the change in begin prices
the formula is change_in_price=(todays_begin / yesterdays_begin) * 100
i wrote the following query but it seems not working. please advise me on what i am doing wrong.. also is the approach wrong ?
please advise.
select date, item_code, begin_price, first_value(begin_price) over (partition by date, item_code order by trunc(date) desc rows between 2 preceding and 1 preceding) as yesterdays_begin
from item_tracker
here, the partition by column is not showing any value.
is there any way i can include the date ? (like a 'having clause' for group by, what is the method to partition by)
i tried range between as well. it reurned the error that i need to mention a number value instead of date to check a range.
please help me :(
thanx in advance
Yes, joins are effective :
SQL> create table item_tracker(price_date date, item_id number, day_price number);
Table created.
SQL> insert into item_tracker values ('11-JAN-11',1,10);
1 row created.
SQL> insert into item_tracker values ('11-JAN-11',2,12);
1 row created.
SQL> insert into item_tracker values ('11-JAN-11',3,24);
1 row created.
SQL> insert into item_tracker values ('12-JAN-11',1,10.5);
1 row created.
SQL> insert into item_tracker values ('12-JAN-11',2,16);
1 row created.
SQL> insert into item_tracker values ('12-JAN-11',3,21);
1 row created.
SQL> commit;
Commit complete.
SQL>
SQL> l
1 select a.item_id, a.price_date, a.day_price, b.day_price PrevPrice, (a.day_price - b.day_price) PriceDiff
2 from item_tracker a, item_tracker b
3 where a.item_id=b.item_id
4 and a.price_date=to_date('12-JAN-11','DD-MON-RR')
5 and b.price_date=a.price_date-1
6* order by 1
SQL> /
ITEM_ID PRICE_DAT DAY_PRICE PREVPRICE PRICEDIFF
1 12-JAN-11 10.5 10 .5
2 12-JAN-11 16 12 4
3 12-JAN-11 21 24 -3
SQL>Hemant K Chitale
Similar Messages
-
Missing partition by clause causing wrong aggregation
Hello all!
I have a Location Hierarchy. Country Region > Country > State > City
When I create a report using Country, Headcount ( Month = July 11) I get correct results with right aggregation:
United States 2000
Mexico 1500
Ireland 1000
SQL Generated:
WITH
SAWITH0 AS (select T95996.COUNTRY_NAME as c2,
T95996.COUNTRY_CODE as c3,
sum(T158903.HEADCOUNT) as c4,
T100027.PER_NAME_MONTH as c5
from
W_BUSN_LOCATION_D T95996,
W_EMPLOYMENT_D T95816,
W_MONTH_D T100027,
W_WRKFC_EVT_MONTH_F T158903
where ( T95816.ROW_WID = T158903.EMPLOYMENT_WID
and T95996.ROW_WID = T158903.LOCATION_WID
and T100027.ROW_WID = T158903.EVENT_MONTH_WID
and T100027.PER_NAME_MONTH = '2011 / 08'
group by T95996.COUNTRY_CODE, T95996.COUNTRY_NAME, T100027.PER_NAME_MONTH),
SAWITH1 AS (select distinct SAWITH0.c2 as c1,
LAST_VALUE(SAWITH0.c4 IGNORE NULLS) OVER (PARTITION BY SAWITH0.c3 ORDER BY SAWITH0.c3 NULLS FIRST, SAWITH0.c5 NULLS FIRST ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as c2,
SAWITH0.c3 as c3
from
SAWITH0)
select SAWITH1.c1 as c1,
SAWITH1.c2 as c2
from
SAWITH1
order by c1
When I create a report using Country Region, Headcount ( Month = July 11) I get wrong aggregation and all rows show same number
Region 1- 135000
Region 2- 135000
Region 3- 135000
SQL Generated:
WITH
SAWITH0 AS (select T95996.COUNTRY_REGION as c2,
sum(T158903.HEADCOUNT) as c3,
T100027.PER_NAME_MONTH as c4
from
W_EMPLOYMENT_D T95816,
W_MONTH_D T100027,
W_WRKFC_EVT_MONTH_F T158903,
W_BUSN_LOCATION_D T95996
where ( T95816.ROW_WID = T158903.EMPLOYMENT_WID
and T100027.ROW_WID = T158903.EVENT_MONTH_WID
and T100027.PER_NAME_MONTH = '2011 / 08'
group by T95996.COUNTRY_REGION, T100027.PER_NAME_MONTH)
select distinct SAWITH0.c2 as c1,
LAST_VALUE(SAWITH0.c3 IGNORE NULLS) OVER ( ORDER BY SAWITH0.c4 NULLS FIRST ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as c2
from
SAWITH0
order by c1
I see that the second SQL is missing that PARTITION BY CLAUSE and wondering if this is reason for wrong calculation. How can I make BI Server to include this clause?
Any leads will be helpful.Hi Deepak,
Thanks for your reply. I see your point here.
Some more info: This fact table is actually a monthly snapshot. Do you think I should check on anything else?
I tried to simply the SQL Generated by I Server by removing some extra conditions. Here is the actual SQL for Country, Headcount:
WITH
SAWITH0 AS (select T95996.COUNTRY_NAME as c2,
T95996.COUNTRY_CODE as c3,
sum(case when T95816.W_EMPLOYMENT_STAT_CODE = 'A' and T95816.W_EMPLOYEE_CAT_CODE = 'EMPLOYEE' then T158903.HEADCOUNT else 0 end ) as c4,
T100027.PER_NAME_MONTH as c5
from
W_BUSN_LOCATION_D T95996 /* Dim_W_BUSN_LOCATION_D_Employee */ ,
W_EMPLOYMENT_D T95816 /* Dim_W_EMPLOYMENT_D */ ,
W_MONTH_D T100027 /* Dim_W_MONTH_D */ ,
W_WRKFC_EVT_MONTH_F T158903 /* Fact_W_WRKFC_EVT_MONTH_F_Snapshot */
where ( T95816.ROW_WID = T158903.EMPLOYMENT_WID and T95996.ROW_WID = T158903.LOCATION_WID and T100027.ROW_WID = T158903.EVENT_MONTH_WID and T100027.PER_NAME_MONTH = '2011 / 07' and T158903.SNAPSHOT_IND = 1 and T158903.DELETE_FLG <> 'Y' and T100027.CAL_MONTH_START_DT >= TO_DATE('2004-01-01 00:00:00' , 'YYYY-MM-DD HH24:MI:SS') and (T158903.SNAPSHOT_MONTH_END_IND in (1) or T158903.EFFECTIVE_END_DATE >= TO_DATE('2011-08-11 00:00:00' , 'YYYY-MM-DD HH24:MI:SS')) and (T95996.ROW_WID in (0) or T95996.BUSN_LOC_TYPE in ('EMP_LOC')) and T158903.EFFECTIVE_START_DATE <= TO_DATE('2011-08-11 00:00:00' , 'YYYY-MM-DD HH24:MI:SS') )
group by T95996.COUNTRY_CODE, T95996.COUNTRY_NAME, T100027.PER_NAME_MONTH),
SAWITH1 AS (select distinct SAWITH0.c2 as c1,
LAST_VALUE(SAWITH0.c4 IGNORE NULLS) OVER (PARTITION BY SAWITH0.c3 ORDER BY SAWITH0.c3 NULLS FIRST, SAWITH0.c5 NULLS FIRST ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as c2,
SAWITH0.c3 as c3
from
SAWITH0)
select SAWITH1.c1 as c1,
SAWITH1.c2 as c2
from
SAWITH1
order by c1
for Country Region, Headcount:
WITH
SAWITH0 AS (select T95996.COUNTRY_REGION as c2,
sum(case when T95816.W_EMPLOYMENT_STAT_CODE = 'A' and T95816.W_EMPLOYEE_CAT_CODE = 'EMPLOYEE' then T158903.HEADCOUNT else 0 end ) as c3,
T100027.PER_NAME_MONTH as c4
from
W_EMPLOYMENT_D T95816 /* Dim_W_EMPLOYMENT_D */ ,
W_MONTH_D T100027 /* Dim_W_MONTH_D */ ,
W_WRKFC_EVT_MONTH_F T158903 /* Fact_W_WRKFC_EVT_MONTH_F_Snapshot */ ,
W_BUSN_LOCATION_D T95996 /* Dim_W_BUSN_LOCATION_D_Employee */
where ( T95816.ROW_WID = T158903.EMPLOYMENT_WID and T100027.ROW_WID = T158903.EVENT_MONTH_WID and T100027.PER_NAME_MONTH = '2011 / 07' and T158903.SNAPSHOT_IND = 1 and T158903.DELETE_FLG <> 'Y' and T100027.CAL_MONTH_START_DT >= TO_DATE('2004-01-01 00:00:00' , 'YYYY-MM-DD HH24:MI:SS') and (T158903.SNAPSHOT_MONTH_END_IND in (1) or T158903.EFFECTIVE_END_DATE >= TO_DATE('2011-08-11 00:00:00' , 'YYYY-MM-DD HH24:MI:SS')) and (T95996.ROW_WID in (0) or T95996.BUSN_LOC_TYPE in ('EMP_LOC')) and T158903.EFFECTIVE_START_DATE <= TO_DATE('2011-08-11 00:00:00' , 'YYYY-MM-DD HH24:MI:SS') )
group by T95996.COUNTRY_REGION, T100027.PER_NAME_MONTH)
select distinct SAWITH0.c2 as c1,
LAST_VALUE(SAWITH0.c3 IGNORE NULLS) OVER ( ORDER BY SAWITH0.c4 NULLS FIRST ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as c2
from
SAWITH0
order by c1 -
How to group the values with this partition over clause ?
Hi,
I have a nice request :
select c.libelle "Activité", sum(b.duree) "Durée"
from fiche a, activite_faite b,
activites c, agent d
where a.date_activite
BETWEEN TO_DATE('20/09/2009', 'DD/MM/YYYY') AND TO_DATE('26/10/2009', 'DD/MM/YYYY')
AND a.agent_id = 104
AND a.fiche_id = b.fiche_id
AND b.activites_id = c.activites_id
AND a.agent_id = d.agent_id
group by c.libelle
order by sum(b.duree)It gives me this nice result :
ACTIVITE DUREE
Tonte 27I want to get a percentage, i use ratio_to_report
select a.fiche_id, c.libelle "Activité", ratio_to_report(duree) over (partition by c.activites_id) * 100 "Durée"
from fiche a, activite_faite b,
activites c, agent d
where a.date_activite
BETWEEN TO_DATE('20/09/2009', 'DD/MM/YYYY') AND TO_DATE('26/10/2009', 'DD/MM/YYYY')
AND a.agent_id = 104
AND a.fiche_id = b.fiche_id
AND b.activites_id = c.activites_id
AND a.agent_id = d.agent_idIt gives me this less nice result :
Tonte 7,40740740740740740740740740740740740741
Tonte 33,33333333333333333333333333333333333333
Tonte 33,33333333333333333333333333333333333333
Tonte 25,92592592592592592592592592592592592593I would like to get this result :
Tonte 100I tried "grouping" values in the partition over clause but without success.
Any help appreciated from the slq-masters :
Regards,
ChristianChristian from France wrote:
I would like to get this result :
Tonte 100
Hi,
Why not this
select c.libelle "Activité", 100 "Durée"
from fiche a, activite_faite b,
activites c, agent d
where a.date_activite
BETWEEN TO_DATE('20/09/2009', 'DD/MM/YYYY') AND TO_DATE('26/10/2009', 'DD/MM/YYYY')
AND a.agent_id = 104
AND a.fiche_id = b.fiche_id
AND b.activites_id = c.activites_id
AND a.agent_id = d.agent_id
group by c.libelle
order by sum(b.duree)Because it would always be 100 (if you are taking as percentage) be what ever the count of duree be.
Or did I miss something in understanding the requirement.
Regards
Anurag -
Dose the Partition by clause increase the perfomance then the normal group by clause ??
thanks,
Raj.Analytic queries != Aggregate queries
Therefore it depends on what you're doing as to whether you'd want to use Analytic vs Aggregate queries.
Performance depends also on the amount of data in your tables.
Having said that, Analytics can mean that a self-join is no longer needed, and this could help if a large table is involved ... on the otherhand, it might hinder.
Think of Analytic queries as another tool in your toolbox; sometimes a hammer is the right tool to use, but sometimes you need a spanner instead. -
Cross-listing Query (Partition By Clause? Self-Join?)
Hello,
I need a query that will cross-list courses a professor is teaching this semester. Essentially, two fields need to be the same (i.e.: Section & CourseTitle), while the third field is different (i.e.: Subject).
For example, Max Power is a professor teaching 3 courses, one is cross-listed (ENG 123 and JRL 123):
LastName FirstName Subject Section CourseTitle
Power Max ENG 123 English Composition
Power Max ENG 452 Robert Frost Poetry
Power Max JRL 123 English Composition
Power Max ENG 300 Faulkner & TwainThe desired query output is this:
LastName FirstName Subject Section CourseTitle
Power Max ENG 123 English Composition
Power Max JRL 123 English CompositionBasically, I need only the cross-listed courses in the output.Is this an instance where I use a "Partition By Clause" or should I create a self-join?
Much thanks for any help and comments.Unfortunately, I can't create new tables. I don't have permission. I can't alter, add or delete any of the data.
So I tried Frank's code with my data:
WITH got_cnt AS
SELECT sivasgn_term_code, spriden_id, spriden_last_name, spriden_first_name,
ssbsect_ptrm_code, ssbsect_camp_code,
sivasgn_crn, ssbsect_subj_code, ssbsect_crse_numb, scbcrse_title,
count(*) over (partition by ssbsect_crse_numb, scbcrse_title) cnt
FROM spriden INNER JOIN sivasgn ON spriden_pidm = sivasgn_pidm JOIN
ssvsect ON ssbsect_crn = sivasgn_crn JOIN
sfrstcr ON sfrstcr_crn = sivasgn_crn
WHERE ssbsect_term_code= sivasgn_term_code
AND sfrstcr_term_code = sivasgn_term_code
AND ssbsect_enrl > '0' and sivasgn_credit_hr_sess > '0'
AND sivasgn_term_code IN ('200901', '200909')
AND spriden_change_ind IS NULL
AND ssbsect_camp_code IN ('1', '2', 'A', 'B')
SELECT DISTINCT sivasgn_term_code, spriden_id, spriden_last_name, spriden_first_name,
substr(ssbsect_ptrm_code,1,1) as ptrm_code, ssbsect_camp_code,
sivasgn_crn, ssbsect_subj_code, ssbsect_crse_numb, scbcrse_title
FROM got_cnt
WHERE cnt >1
ORDER BY spriden_last_name, sivasgn_term_code, ssbsect_crse_numb;The output pretty much displays all courses with same subject code, course number and course title.
Output:
LastName FirstName Subject Section CourseTitle
Power Max ENG 123 English Composition
Power Max ENG 123 English Composition
Power Max ENG 452 Robert Frost Poetry
Power Max ENG 452 Robert Frost Poetry
Power Max ENG 300 Faulkner & Twain
Power Max ENG 300 Faulkner & Twain
Power Max JRL 123 English Composition
Power Max JRL 123 English CompositionWhat I would like is same course number, course title, BUT different subject code. Pretty much that in my first post of this thread.
Desired Output:
LastName FirstName Subject Section CourseTitle
Power Max ENG 123 English Composition
Power Max JRL 123 English CompositionMaybe I'm explaining this wrong. Any help would be greatly appreciated. Thanks. -
FileVault2 & no supported helper partition to update
While a workaround for a problem I had fixed the issue, the root cause remains.
I am using FileVault2 full disk encryption. It seems on my system the kernelcache never gets updated after the drive has been encrypted with FileVault. To be exact: The kernelcache on the helper partition 'Recovery HD' never gets updated. The kernelcache in
/System/Library/Caches/com.apple.kext.caches/Startup/kernelcache
gets updated correctly. What's missing is the part to transfer an updated kernelcache to the helper partition. The last lines of output from
kextcache -v 6 -update-volume /
are
Created prelinked kernel //System/Library/Caches/com.apple.kext.caches/Startup/kernelcache.
CSFDE property cache does not need update.
/: no supported helper partitions to update.
So the kernel cache in the encrypted '/' partition is updated, but since there are 'no supported helper partitions to update', the new kernelcache is not copied to the location which is used during boot. At boot, the kernelcache from the helper partition is loaded. Its location is
/Volumes/Recovery\ HD/com.apple.boot.S/System/Library/Caches/com.apple.kext.caches/Startup/kernelc ache
For some reason the helper partition does not seem to be associated with my encrypted root partition. Does anyone know how to associate my helper partition with the encrypted root partition again?
Here is some background about my system and how I installed it:
My Mac has one internal disk. I use it for Time Machine backups only. It is not possible to boot from the internal disk. My system disk is an external SSD connected via USB 3.0.
I installed the system disk by holding CMD-r during boot to get the Mac into Recovery Mode. With Disk Utility I erased the SSD completely, left Disk Utility and installed OS X Mountain Lion 10.8.3. When the installation was finished, I created a temporary admin user and used Migration Assistent to migrate all User accounts and programs from a backup. Then I logged into my user account which Migration Assistent had created, deleted the temporary admin user and activated File Vault. Later, I installed an upgrade for a program that uses a kernel extension. After every boot I got the message, the version of the kernel extension did not match the version of the program. While everything in the encrypted '/' partition had been updated correctly, the kernelcache on the Recovery HD had not. While I can copy the kernelcache to the helper partition manually, I think this a hack and it should happen automatically when the kernelcache is updated in the '/' partition. I am not aware having done somthing that could make Mac OS X loose the association between the '/' partition and the Recovery partition.Yuo can't "undo" the update. Bose support may be your best bet.
-
Error "Building boot caches on boot helper partition failed" when installing Yosemite
I Have a MacBook Pro 8,3 17" and have been running OSX Maverick 10.9.5 quite happily. I finally decided to bite the bullet and update to OSX 10.10.1. I went through the App Store and clicked install on the Yosemite offered there.
THe install took about 55 mins and then right at the end it reported: Building boot caches on boot helper partition failed, install failed.
now i can't boot normally or restore from my time machine backup.
can anybody suggest a fix?Install OS X Using Internet Recovery
Be sure you backup your files to an external drive or second internal drive because the following procedure will remove everything from the hard drive.
Boot to the Internet Recovery HD:
Restart the computer and after the chime press and hold down the COMMAND-OPTION- R keys until a globe appears on the screen. Wait patiently - 15-20 minutes - until the Recovery main menu appears.
Partition and Format the hard drive:
Select Disk Utility from the main menu and click on the Continue button.
After DU loads select your newly installed hard drive (this is the entry with the mfgr.'s ID and size) from the left side list. Click on the Partition tab in the DU main window.
Under the Volume Scheme heading set the number of partitions from the drop down menu to one. Click on the Options button, set the partition scheme to GUID then click on the OK button. Set the format type to Mac OS Extended (Journaled.) Click on the Partition button and wait until the process has completed. Quit DU and return to the main menu.
Reinstall OS X: Select Reinstall OS X and click on the Install button. Be sure to select the correct drive to use if you have more than one.
Note: You will need an active Internet connection. I suggest using Ethernet if possible because it is three times faster than wireless.
This should restore the version of OS X originally pre-installed on the computer. -
Erzeugen von Boot-Caches auf der Boot-Helper-Partition ist fehlgeschlagen.
Ich bekomme neuerdings - nach Installation einer Sonnet SSD Pro mit 2 SSD's folgende Fehlermeldung bei der Auswahl des Startlaufwerks:
Sie können dieses Volume nicht als Startvolume festlegen. Erzeugen von Boot-Caches auf der Boot-Helper-Partition ist fehlgeschlagen.
Starten funktioniert auch nur nach hochstarten mit gedrückter option-Taste und manueller Auswahl des Startlaufwerks ... Hilfe ...Do you have both W7 and W8 on the iMac? If not, depending on your specific Mac model/year, the correct Bootcamp drivers can be downloaded and installed in W8/Bootcamp.
You can download the appropriate drivers by using Bootcamp Assistant and put them on a USB drive. -
Hi Gurus,
Can someone please help me out.
I've a below tables.
1) tbl_link --> this table contains information at profile level
2) tbl_summary --> this table contains summary at parent profile level derived from tbl_link table
One parent profile contains multiple child profiles and each child profile links to a code (which is B, W, G or P) and the code is linked to a category (i.e. ONL and OFL). In this case code B is linked to category 'ONL' and codes W,G,P linked to OFL category.
ONL category needs 100 points. If it don't have enough points then i need to borrow from OFL category which i'm doing and populating into tbl_summary table at parent profile level.
Now i need to insert data into tbl_link table at profile level with howmany points used, expired based on tbl_summary table. Rule is at the end of month if we add points for each profile in tbl_link table it should come as 0.
with
tbl_SUMMARY as
select 1 as ppid,'ONL' as catgcode, 53 as earned_points,47 BORROWED_POINTS,100 CERT_POINTS,0 DISCARD_POINTS,100 used from dual
union
select 1 as ppid,'OFL' as catgcode, 223 as earned_points,0 BORROWED_POINTS,176 CERT_POINTS,76 DISCARD_POINTS,100 used from dual
union
select 2 as ppid,'ONL' as catgcode, 39 as earned_points,61 BORROWED_POINTS,100 CERT_POINTS,0 DISCARD_POINTS,100 used from dual
union
select 2 as ppid,'OFL' as catgcode, 90 as earned_points,0 BORROWED_POINTS,29 CERT_POINTS,29 DISCARD_POINTS,100 used from dual
union
select 3 as ppid,'ONL' as catgcode, 109 as earned_points,0 BORROWED_POINTS,109 CERT_POINTS,9 DISCARD_POINTS,100 used from dual
union
select 3 as ppid,'OFL' as catgcode, 223 as earned_points,0 BORROWED_POINTS,223 CERT_POINTS,23 DISCARD_POINTS,200 used from dual
union
select 4 as ppid,'ONL' as catgcode, 109 as earned_points,0 BORROWED_POINTS,109 CERT_POINTS,9 DISCARD_POINTS,100 used from dual
union
select 4 as ppid,'OFL' as catgcode, 169 as earned_points,0 BORROWED_POINTS,169 CERT_POINTS,69 DISCARD_POINTS,100 used from dual
tbl_link as
select 1 as ppid,1 as pid, 'B' as code,'ONL' as catgcode, 53 as earned_points from dual
union
select 1 as ppid,12 as pid, 'W' as code,'OFL' as catgcode, 26 as earned_points from dual
union
select 1 as ppid,13 as pid, 'G' as code,'OFL' as catgcode, 87 as earned_points from dual
union
select 1 as ppid,14 as pid, 'P' as code,'OFL' as catgcode, 110 as earned_points from dual
union
select 2 as ppid,2 as pid, 'B' as code,'ONL' as catgcode, 39 as earned_points from dual
union
select 2 as ppid,22 as pid, 'W' ,'OFL' as catgcode, 30 as earned_points from dual
union
select 2 as ppid,23 as pid, 'G' ,'OFL' as catgcode, 29 as earned_points from dual
union
select 2 as ppid,24 as pid, 'P' ,'OFL' as catgcode, 31 as earned_points from dual
union
select 3 as ppid,3 as pid, 'B' as code,'ONL' as tier_catgcode, 109 as earned_points from dual
union
select 3 as ppid,32 as pid, 'W' ,'OFL' , 26 as earned_points from dual
union
select 3 as ppid,33 as pid, 'G' ,'OFL', 87 as earned_points from dual
union
select 3 as ppid,34 as pid, 'P' ,'OFL' , 110 as earned_points from dual
union
select 4 as ppid,4 as pid, 'B' as code,'ONL' as catgcode, 109 as earned_points from dual
union
select 4 as ppid,42 as pid, 'W' as code,'OFL' , 26 as earned_points from dual
union
select 4 as ppid,43 as pid, 'G' as code,'OFL' , 87 as earned_points from dual
union
select 4 as ppid,44 as pid, 'P' as code,'OFL' , 56 as earned_points from dual
final (PARENT_PROFILE_ID,PROFILE_ID,catgcode,EARNED_POINTS,BORROWED_POINTS,CERT_POINTS,DISCARD_POINTS,USED)
as (
select A.PPID PARENT_PROFILE_ID,B.PID PROFILE_ID,A.catgcode,B.EARNED_POINTS,BORROWED_POINTS,CERT_POINTS,DISCARD_POINTS,USED
from tbl_SUMMARY a,tbl_link b where a.ppid=b.ppid AND A.catgcode=B.catgcode
ORDER BY PROFILE_ID
select * from final order by 1;
PARENT_PROFILE_ID PROFILE_ID CATGCODE EARNED_POINTS BORROWED_POINTS CERT_POINTS DISCARD_POINTS USED
1 1 ONL 53 47 100 0 100
1 14 OFL 110 0 176 76 100
1 13 OFL 87 0 176 76 100
1 12 OFL 26 0 176 76 100
2 2 ONL 39 61 100 0 100
2 24 OFL 31 0 29 29 100
2 23 OFL 29 0 29 29 100
2 22 OFL 30 0 29 29 100
3 32 OFL 26 0 223 23 200
3 33 OFL 87 0 223 23 200
3 34 OFL 110 0 223 23 200
3 3 ONL 109 0 109 9 100
4 42 OFL 26 0 169 69 100
4 43 OFL 87 0 169 69 100
4 44 OFL 56 0 169 69 100
4 4 ONL 109 0 109 9 100
Need Output as below :
For parent profile 1, whatever i mentioned above is not correct. Borrowed 47 points from OFL to ONL to make ONL and also from OFL category has 176 points remaining after lending to ONL and using only 100 points, remaining 76 points are discarded. Need to deduct these 76 points also from child profiles. Output will be as below.
PARENT_PROFILE_ID PROFILE_ID CATGCODE EARNED_POINTS BORROWED_POINTS CERT_POINTS DISCARD_POINTS USED BURN_PTS EXPIRE_PTS
1 1 ONL 53 47 100 0 100 -53 0
1 12 OFL 26 0 176 76 100 -26 0
1 13 OFL 87 0 176 76 100 -74 -13
1 14 OFL 110 0 176 76 100 -47 -63
For parent profile id 2 --> ONL category has 39 points, so borrowed 61 points from OFL category to make ONL points 100.
Now need to populate tbl_link table at child profile level (i.e. child profiles 22,23,24).
Borrowed 61 points from OFL and need to deduct this points from the profile which has highest earned points, in this case deduct from profile 24 which has 31 points, from profile 22 which has 30 points. Need output like below
PARENT_PROFILE_ID PROFILE_ID CATGCODE EARNED_POINTS BORROWED_POINTS CERT_POINTS DISCARD_POINTS USED BURN_PTS EXPIRE_PTS
2 2 ONL 39 61 100 0 100 -39 0
2 22 OFL 30 0 29 29 100 -30 0
2 23 OFL 29 0 29 29 100 0 -29
2 24 OFL 31 0 29 29 100 -31 0
For parent profile id 3 --> ONL category has 109 points, so no need to borrow points from OFL category
Now need to populate tbl_link table at child profile level (i.e. child profiles 32,33,34).
in this case ONL has 100 points, so move the remaining 9 points will be expired. OFL category has 223 points total. need only 200 points (i.e. mutiple of 100) for our process, 23 points will be expired and has to deduct from the profile which has highest earned points, in this case from profile 34. Output :
PARENT_PROFILE_ID PROFILE_ID CATGCODE EARNED_POINTS BORROWED_POINTS CERT_POINTS DISCARD_POINTS USED BURN_PTS EXPIRE_PTS
3 3 ONL 109 0 109 9 100 -100 -9
3 32 OFL 26 0 223 23 200 -26 0
3 33 OFL 87 0 223 23 200 -87 0
3 34 OFL 110 0 223 23 200 -87 -23
For parent profile id 4 --> ONL category has 109 points, so no need to borrow points from OFL category
Now need to populate tbl_link table at child profile level (i.e. child profiles 42,43,44).
in this case ONL has 100 points, so move the remaining 9 points will be expired. OFL category has 169 points total. need only 100 points (i.e. mutiple of 100) for our process, 69 points will be expired and has to deduct from the profile which has highest earned points, in this case from profile 43. Output :
PARENT_PROFILE_ID PROFILE_ID CATGCODE EARNED_POINTS BORROWED_POINTS CERT_POINTS DISCARD_POINTS USED BURN_PTS EXPIRE_PTS
4 4 ONL 109 0 109 9 100 100 9
4 42 OFL 26 0 169 69 100 -26 0
4 43 OFL 87 0 169 69 100 -18 -69
4 44 OFL 56 0 169 69 100 -56 0
Can someone help with the query. I googled about looping in sql and came to know that Oracle has a feature MODEL to loop in SQL, but i don't have idea on using MODEL clause.
Appreciate your help!
Thanks
SriHi Gurus,
Can someone please help me out.
I've a below tables.
1) tbl_link --> this table contains information at profile level
2) tbl_summary --> this table contains summary at parent profile level derived from tbl_link table
One parent profile contains multiple child profiles and each child profile links to a code (which is B, W, G or P) and the code is linked to a category (i.e. ONL and OFL). In this case code B is linked to category 'ONL' and codes W,G,P linked to OFL category.
ONL category needs 100 points. If it don't have enough points then i need to borrow from OFL category which i'm doing and populating into tbl_summary table at parent profile level.
Now i need to insert data into tbl_link table at profile level with howmany points used, expired based on tbl_summary table. Rule is at the end of month if we add points for each profile in tbl_link table it should come as 0.
with
tbl_SUMMARY as
select 1 as ppid,'ONL' as catgcode, 53 as earned_points,47 BORROWED_POINTS,100 CERT_POINTS,0 DISCARD_POINTS,100 used from dual
union
select 1 as ppid,'OFL' as catgcode, 223 as earned_points,0 BORROWED_POINTS,176 CERT_POINTS,76 DISCARD_POINTS,100 used from dual
union
select 2 as ppid,'ONL' as catgcode, 39 as earned_points,61 BORROWED_POINTS,100 CERT_POINTS,0 DISCARD_POINTS,100 used from dual
union
select 2 as ppid,'OFL' as catgcode, 90 as earned_points,0 BORROWED_POINTS,29 CERT_POINTS,29 DISCARD_POINTS,100 used from dual
union
select 3 as ppid,'ONL' as catgcode, 109 as earned_points,0 BORROWED_POINTS,109 CERT_POINTS,9 DISCARD_POINTS,100 used from dual
union
select 3 as ppid,'OFL' as catgcode, 223 as earned_points,0 BORROWED_POINTS,223 CERT_POINTS,23 DISCARD_POINTS,200 used from dual
union
select 4 as ppid,'ONL' as catgcode, 109 as earned_points,0 BORROWED_POINTS,109 CERT_POINTS,9 DISCARD_POINTS,100 used from dual
union
select 4 as ppid,'OFL' as catgcode, 169 as earned_points,0 BORROWED_POINTS,169 CERT_POINTS,69 DISCARD_POINTS,100 used from dual
tbl_link as
select 1 as ppid,1 as pid, 'B' as code,'ONL' as catgcode, 53 as earned_points from dual
union
select 1 as ppid,12 as pid, 'W' as code,'OFL' as catgcode, 26 as earned_points from dual
union
select 1 as ppid,13 as pid, 'G' as code,'OFL' as catgcode, 87 as earned_points from dual
union
select 1 as ppid,14 as pid, 'P' as code,'OFL' as catgcode, 110 as earned_points from dual
union
select 2 as ppid,2 as pid, 'B' as code,'ONL' as catgcode, 39 as earned_points from dual
union
select 2 as ppid,22 as pid, 'W' ,'OFL' as catgcode, 30 as earned_points from dual
union
select 2 as ppid,23 as pid, 'G' ,'OFL' as catgcode, 29 as earned_points from dual
union
select 2 as ppid,24 as pid, 'P' ,'OFL' as catgcode, 31 as earned_points from dual
union
select 3 as ppid,3 as pid, 'B' as code,'ONL' as tier_catgcode, 109 as earned_points from dual
union
select 3 as ppid,32 as pid, 'W' ,'OFL' , 26 as earned_points from dual
union
select 3 as ppid,33 as pid, 'G' ,'OFL', 87 as earned_points from dual
union
select 3 as ppid,34 as pid, 'P' ,'OFL' , 110 as earned_points from dual
union
select 4 as ppid,4 as pid, 'B' as code,'ONL' as catgcode, 109 as earned_points from dual
union
select 4 as ppid,42 as pid, 'W' as code,'OFL' , 26 as earned_points from dual
union
select 4 as ppid,43 as pid, 'G' as code,'OFL' , 87 as earned_points from dual
union
select 4 as ppid,44 as pid, 'P' as code,'OFL' , 56 as earned_points from dual
final (PARENT_PROFILE_ID,PROFILE_ID,catgcode,EARNED_POINTS,BORROWED_POINTS,CERT_POINTS,DISCARD_POINTS,USED)
as (
select A.PPID PARENT_PROFILE_ID,B.PID PROFILE_ID,A.catgcode,B.EARNED_POINTS,BORROWED_POINTS,CERT_POINTS,DISCARD_POINTS,USED
from tbl_SUMMARY a,tbl_link b where a.ppid=b.ppid AND A.catgcode=B.catgcode
ORDER BY PROFILE_ID
select * from final order by 1;
PARENT_PROFILE_ID PROFILE_ID CATGCODE EARNED_POINTS BORROWED_POINTS CERT_POINTS DISCARD_POINTS USED
1 1 ONL 53 47 100 0 100
1 14 OFL 110 0 176 76 100
1 13 OFL 87 0 176 76 100
1 12 OFL 26 0 176 76 100
2 2 ONL 39 61 100 0 100
2 24 OFL 31 0 29 29 100
2 23 OFL 29 0 29 29 100
2 22 OFL 30 0 29 29 100
3 32 OFL 26 0 223 23 200
3 33 OFL 87 0 223 23 200
3 34 OFL 110 0 223 23 200
3 3 ONL 109 0 109 9 100
4 42 OFL 26 0 169 69 100
4 43 OFL 87 0 169 69 100
4 44 OFL 56 0 169 69 100
4 4 ONL 109 0 109 9 100
Need Output as below :
For parent profile 1, whatever i mentioned above is not correct. Borrowed 47 points from OFL to ONL to make ONL and also from OFL category has 176 points remaining after lending to ONL and using only 100 points, remaining 76 points are discarded. Need to deduct these 76 points also from child profiles. Output will be as below.
PARENT_PROFILE_ID PROFILE_ID CATGCODE EARNED_POINTS BORROWED_POINTS CERT_POINTS DISCARD_POINTS USED BURN_PTS EXPIRE_PTS
1 1 ONL 53 47 100 0 100 -53 0
1 12 OFL 26 0 176 76 100 -26 0
1 13 OFL 87 0 176 76 100 -74 -13
1 14 OFL 110 0 176 76 100 -47 -63
For parent profile id 2 --> ONL category has 39 points, so borrowed 61 points from OFL category to make ONL points 100.
Now need to populate tbl_link table at child profile level (i.e. child profiles 22,23,24).
Borrowed 61 points from OFL and need to deduct this points from the profile which has highest earned points, in this case deduct from profile 24 which has 31 points, from profile 22 which has 30 points. Need output like below
PARENT_PROFILE_ID PROFILE_ID CATGCODE EARNED_POINTS BORROWED_POINTS CERT_POINTS DISCARD_POINTS USED BURN_PTS EXPIRE_PTS
2 2 ONL 39 61 100 0 100 -39 0
2 22 OFL 30 0 29 29 100 -30 0
2 23 OFL 29 0 29 29 100 0 -29
2 24 OFL 31 0 29 29 100 -31 0
For parent profile id 3 --> ONL category has 109 points, so no need to borrow points from OFL category
Now need to populate tbl_link table at child profile level (i.e. child profiles 32,33,34).
in this case ONL has 100 points, so move the remaining 9 points will be expired. OFL category has 223 points total. need only 200 points (i.e. mutiple of 100) for our process, 23 points will be expired and has to deduct from the profile which has highest earned points, in this case from profile 34. Output :
PARENT_PROFILE_ID PROFILE_ID CATGCODE EARNED_POINTS BORROWED_POINTS CERT_POINTS DISCARD_POINTS USED BURN_PTS EXPIRE_PTS
3 3 ONL 109 0 109 9 100 -100 -9
3 32 OFL 26 0 223 23 200 -26 0
3 33 OFL 87 0 223 23 200 -87 0
3 34 OFL 110 0 223 23 200 -87 -23
For parent profile id 4 --> ONL category has 109 points, so no need to borrow points from OFL category
Now need to populate tbl_link table at child profile level (i.e. child profiles 42,43,44).
in this case ONL has 100 points, so move the remaining 9 points will be expired. OFL category has 169 points total. need only 100 points (i.e. mutiple of 100) for our process, 69 points will be expired and has to deduct from the profile which has highest earned points, in this case from profile 43. Output :
PARENT_PROFILE_ID PROFILE_ID CATGCODE EARNED_POINTS BORROWED_POINTS CERT_POINTS DISCARD_POINTS USED BURN_PTS EXPIRE_PTS
4 4 ONL 109 0 109 9 100 100 9
4 42 OFL 26 0 169 69 100 -26 0
4 43 OFL 87 0 169 69 100 -18 -69
4 44 OFL 56 0 169 69 100 -56 0
Can someone help with the query. I googled about looping in sql and came to know that Oracle has a feature MODEL to loop in SQL, but i don't have idea on using MODEL clause.
Appreciate your help!
Thanks
Sri -
Need help in 'WITH CLAUSE' Query
Hello Gurus,
I am trying to calculate the count of distinct members for each provid.
I am using the with clause to get information regarding the provid.
WITH T AS
(SELECT a.UD_ID MRR_ID,
A.UD_LASTNAME LAST_NAME,
A.UD_FIRSTNAME FIRST_NAME,
COUNT(DISTINCT DP.PA_PROVIDERID) PROVIDERS_ASSIGNED
FROM (SELECT UD.UD_ID,
UD_LASTNAME,
UD_FIRSTNAME
FROM USER_DETAILS UD,
MAP_USERS_TO_ROLES MR
WHERE MR.MUR_UR_ID_REF = 1000
AND MR.MUR_UD_ID_REF = UD.UD_ID) A,
D4C_PROVIDER_ASSIGNMENT DP
WHERE A.UD_ID = DP.PA_ASSIGNEDTO
AND dp.pa_status ='A'
GROUP BY A.UD_ID,
A.UD_LASTNAME,
A.UD_FIRSTNAME
ORDER BY 3 DESC) OUTPUT of just above query without WITH clause.
MRR_ID LAST_NAME FIRST_NAME PROVIDERS_ASSIGNED
1229 mrrTest mrrTest 4
1228 mrr2Last mrr2First 5
1230 mrr1Last mrr1First 7
1226 Panwar SIngh 1
1181 MRRLast MRRTest 4
1221 One MRR 1
1322 Thakuria Bibhuthi 2I am creating this and get all the information to show on front end. Now I want to calculate the no of members as per the providers assigned for each MRR_ID
Below query show the no of members for all the providers assigned to a provider.
ex:
SELECT * FROM (
SELECT COUNT(DISTINCT dmpc_hicn) countmember
FROM D4C_HICN_PROVIDER_claims a WHERE trim(DPMC_PROVIDER_NO) IN
(SELECT trim(pa_providerid)
FROM d4c_provider_assignment
WHERE pa_assignedto = 1181 (mrr_id) --here i have use the mrrid from with clause and get the member count with all the columns coming from WITH CLAUSE.
AND pa_roleid = 1000
AND PA_STATUS ='A'
GROUP BY a.dmpc_ss_id_ref)Right now I am using materialized view i dont wanna use the same..
I am sending the materialized view code as well what i am doing ..
( SELECT SUM(member_count)member_count_bynpi ,mrr_id FROM (
(SELECT count(DISTINCT hp.dmpc_hicn) member_count,hp.DMPC_SS_ID_REF ,a1.ud_id mrr_id FROM D4C_HICN_PROVIDER_claims hp ,
(SELECT a.UD_ID ,DP.PA_PROVIDERID
FROM (SELECT UD.UD_ID, UD_LASTNAME, UD_FIRSTNAME
FROM USER_DETAILS UD, MAP_USERS_TO_ROLES MR
WHERE MR.MUR_UR_ID_REF = 1000
AND MR.MUR_UD_ID_REF = UD.UD_ID) A,
D4C_PROVIDER_ASSIGNMENT DP
WHERE A.UD_ID = DP.PA_ASSIGNEDTO
AND dp.pa_status ='A'
/*AND dp.PA_ASSIGNEDTO = 1221*/) a1
WHERE trim(a1.PA_PROVIDERID) = trim(hp.dpmc_provider_no)
GROUP BY a1.ud_id,hp.DMPC_SS_ID_REF))
GROUP BY mrr_id)Please help me to write the code with the materialized view. Thanks in Advance.
Kind regards,
UP
Edited by: BluShadow on 22-Aug-2011 07:58
fixed {noformat}{noformat} tags. Please use lowercase "code" rather than uppercase "CODE" in the tags.Probably, this may help
WITH T1 as(
SELECT UD.UD_ID,
UD_LASTNAME,
UD_FIRSTNAME
FROM USER_DETAILS UD, MAP_USERS_TO_ROLES MR
WHERE MR.MUR_UR_ID_REF = 1000
AND MR.MUR_UD_ID_REF = UD.UD_ID)
T2 as (SELECT a.UD_ID ,DP.PA_PROVIDERID
FROM T1 A, D4C_PROVIDER_ASSIGNMENT DP
WHERE A.UD_ID = DP.PA_ASSIGNEDTO
AND dp.pa_status ='A')
T3 as(SELECT count(DISTINCT hp.dmpc_hicn) member_count,
hp.DMPC_SS_ID_REF ,
a1.ud_id mrr_id
FROM T2 A1 ,D4C_HICN_PROVIDER_claims hp
WHERE trim(a1.PA_PROVIDERID) = trim(hp.dpmc_provider_no)
GROUP BY a1.ud_id,hp.DMPC_SS_ID_REF)
SELECT SUM(member_count)member_count_bynpi ,mrr_id from T3
GROUP BY mrr_id -
[SOLVED] Chromebook: help partitioning /dev/sda7 to install GRUB
My goal is to dual boot Arch and Chrome OS on an Acer C720. I repartitioned the drive using the Chrubuntu script. Following the Wiki, I created the file system for Arch on /dev/sda7.
The next step in the Wiki reads
Following the instructions for installing GRUB on GPT, use gdisk to create a 1007kb partition and set the type to EF02.
I don't understand what to do. Do I really make another partition on sda? I've read that if you change the partitioning, it will not boot into Chrome OS.
Can someone please help me understand how to create the 1007kb partition for GRUB? Thanks!!
Last edited by Watney (2015-05-10 00:32:05)There aren't details of what you've done, think of what we can comment here.
What says
# parted -l /dev/sdX ### could be /dev/sda
Or even better what's your actual partitioning scheme and how the partitions are laid out.
The note is clear (for me) and the link in it will show more details. The real point is to have the Post-MBR gap where GRUB will use to write its files.
If you don't have that Post-MBR gap then you need to shrink the first partition from the beginning to leave that Mb gap. -
Hi,
I am a newbie on Oracle and I need help on this problem:
I have a data block in a form and I need to insert in the Property 'WHERE CLAUSE' a where clause based on the conditions:
1) ANA_TYPE := TXT_ANA_TYPE AND ANA_CODE := TXT_ANA_CODE. The two variable are initialized in Header Block. No problem for this.
2) The other Where clause depend from an other variable of the Header Block . For example:
If :SITUATION = 1 then the clause must be AND DOC_PAID <> 0
if :SITUATION = 2 then the clause must be AND DOC_PAID = 0
if :SITUATION = 3 then the clause must be AND DOC_INS <> 0
Is possible to create a unique Where clause with this conditions ? If Yes How?
I hope...
Best Regards
Gaetanoand abs(sign(doc_paid)) = abs(sign(:situation-2))Also beware when you are using the where clause property in Forms. Make sure you refer to the Forms-fields and not to its contents.
So use 'field1 = :block.item1' and not 'field1 = ' || :block.item1
The first one used bind variables and will therefore share the plan of the query stored in the library cache, the latter one doesn't and will leave you with lots of unique statements that will thrash your shared_pool and will ultimately kill the performance.
Regards,
Rob. -
Group by Vs Partition By Clause
Hello,
Can you please help me in resolving the below issue,
I have explained the scenario below with dummy table,
CREATE TABLE emp (empno NUMBER(12), ename VARCHAR2(10), deptno NUMBER(12));
INSERT INTO emp
(empno, ename, deptno
VALUES (1, 'A', 10
INSERT INTO emp
(empno, ename, deptno
VALUES (2, 'B', 10
INSERT INTO emp
(empno, ename, deptno
VALUES (3, 'C', 20
INSERT INTO emp
(empno, ename, deptno
VALUES (4, 'D', 20
INSERT INTO emp
(empno, ename, deptno
VALUES (5, 'E', 30
COMMIT ;
SELECT DISTINCT deptno, SUM (empno) / SUM (empno) OVER (PARTITION BY deptno)
FROM emp
GROUP BY deptno;
ORA-00979: not a GROUP BY expression
Earlier i had the query like
SELECT DISTINCT deptno, SUM (empno) OVER (PARTITION BY deptno,empno) / SUM (empno) OVER (PARTITION BY deptno)
FROM emp;
which executed successfully with wrong result.
Please guide me how to resolve this issue,
Thanks,
SanthoshHi,
santhosh.shivaram wrote:
Hello all, sorry for the providing the limited data, I have now depicting the actual data set and the current select query which is giving error and desired output. Please let me know if you need further information on this.
/* Formatted on 2012/09/14 08:00 (Formatter Plus v4.8.8) */ ...If you're going to the trouble of formatting the data, post it inside \ tags, so that this site won't remove the formatting. See the forum FAQ {message:id=9360002}
**Current query:**
SELECT rep_date, cnty, loc, component_code,
SUM (volume) / SUM (volume) OVER (PARTITION BY rep_date, cnty, loc)This is the same problem you had before, and was explained in the first answer {message:id=10573091} Don't you read the replies you get?SUM (volume) OVER (PARTITION BY rep_date, cnty, loc)
can't be used in this GROUP BY query, because it depends on volume, and volume isn't one of the GROUP BY expressions.
FROM table1
GROUP BY rep_date, cnty, loc, component_code;
when execute this query i am getting "ORA-00979: not a GROUP BY expression" error
My desired output_Formatting is especially important for the output. Which do you think is easier to read and understand: what you posted:
Rep_Date Cnty Loc Component_Code QTY_VOL
9/12/2012 2 1 CONTRACT -0.019000516
9/12/2012 2 1 CONTRACT -0.019000516
9/12/2012 2 1 NON-CONTRACT -0.893525112
9/12/2012 2 1 NON-CONTRACT -0.89322
9/12/2012 2 1 CONTRACT-INDEX 1.912525629
9/12/2012 2 1 CONTRACT-INDEX 1.912526
9/12/2012 2 1 CONTRACT-INDEX 1.912526
9/12/2012 2 4 CONTRACT 0.015197825
9/12/2012 2 4 CONTRACT 0.015198
9/12/2012 2 4 NON-CONTRACT 0.984802175
9/12/2012 2 4 NON-CONTRACT 0.984802or this?Rep_Date Cnty Loc Component_Code QTY_VOL
9/12/2012 2 1 CONTRACT -0.019000516
9/12/2012 2 1 CONTRACT -0.019000516
9/12/2012 2 1 NON-CONTRACT -0.893525112
9/12/2012 2 1 NON-CONTRACT -0.89322
9/12/2012 2 1 CONTRACT-INDEX 1.912525629
9/12/2012 2 1 CONTRACT-INDEX 1.912526
9/12/2012 2 1 CONTRACT-INDEX 1.912526
9/12/2012 2 4 CONTRACT 0.015197825
9/12/2012 2 4 CONTRACT 0.015198
9/12/2012 2 4 NON-CONTRACT 0.984802175
9/12/2012 2 4 NON-CONTRACT 0.984802
Which do you think will lead to more answers? Quicker answers? Better answers?
Please let me know if you need any more information.Explain the results.
How do you compute the qty_vol column? Give a couple of very specific examples, showing step by step how you calculate the values given from the sample data.
What does each row of the output represent? Your query says
GROUP BY rep_date, cnty, loc, component_code;which means the result set will have 1 row for each distinct combiation of rep_date, cnty, loc and component_code, but your desired output has at least 2 rows for every distinct combination of them, and in one case you want 3 rows with the same rep_date, cnty, loc and component_code. How do you decide when you want 2 rows, and when you need 3? Will there be occassions when you need 4 row, or 5, or 1?
All the rows with the same rep_date, cnty, loc and component_code have *nearly* the same qty_vol, but usually not quite the same. Sometimes qty_col is rounded: sometimes it's changed slightly, but not just rounded (-0.893525112 get converted to -0.89322). How do you decide when it's rounded, when it remains the same, and when it's changed to a completely different number? When it's rounded, how do you decide how many digits to round it to?
Edited by: Frank Kulash on Sep 14, 2012 12:44 AM -
Need Help on where clause condition
Hello All,
Thanks in advance::
I have below SQL query which is returning 1500 records when i dont use any condition in where clause(Please see the query below);
SELECT POS_TYPE,
POS_ID,
SUB_ACNT_ID,
CHRG,
DOC,
NULL,
ACNT_RLN,
ACCOUNT_FLODERS_VER,
DM_LSTUPDDT,
DM_BTNUMBER,
DM_USERID,
DM_WSID,
STAT_FLG,
SERVICES_FLG,
SERVICES,
INTRST_COND,
PST_INSTRN
FROM &&SRC.ACCOUNT_FOLDERS,
&&SRC.DB;
Output: 15 rows retured
And when i validate the data by putting some conditions in where clause , it is giving 1499 records ( Please see the query below with condition )
SELECT POS_TYPE,
POS_ID,
SUB_ACNT_ID,
CHRG,
DOC,
NULL,
ACNT_RLN,
ACCOUNT_FLODERS_VER,
DM_LSTUPDDT,
DM_BTNUMBER,
DM_USERID,
DM_WSID,
STAT_FLG,
SERVICES_FLG,
SERVICES,
INTRST_COND,
PST_INSTRN
FROM &&SRC.ACCOUNT_FOLDERS,
&&SRC.DB
WHERE (POS_TYPE,
POS_ID,
SUB_ACNT_ID) IN (SELECT POS_TYPE,
POS_ID,
SUB_ACNT_ID FROM ACCOUNT
WHERE DM_LSTUPDDT > 1_LAST_RUN_DATE OR 1_FIRST_RUN_FLAG=1);
Now, I wanted to know that missing record(1st SQL is giving 1500 rows without any condition & 1nd SQL is giving 1499 rows with condition in where clause)
I am worried and confused to find out the missing record. Tried with different conditions like Not In... nothing worked perfectly.
Could some one please have a look and provide me the correct SQL , Performance wise also it should be good, SQL should not cause any performance issues.
Please help me on it..
Thanks,
MKRDo a minus
SELECT POS_TYPE,
POS_ID,
SUB_ACNT_ID,
CHRG,
DOC,
NULL,
ACNT_RLN,
ACCOUNT_FLODERS_VER,
DM_LSTUPDDT,
DM_BTNUMBER,
DM_USERID,
DM_WSID,
STAT_FLG,
SERVICES_FLG,
SERVICES,
INTRST_COND,
PST_INSTRN
FROM &&SRC.ACCOUNT_FOLDERS, &&SRC.DB;
MINUS
SELECT POS_TYPE,
POS_ID,
SUB_ACNT_ID,
CHRG,
DOC,
NULL,
ACNT_RLN,
ACCOUNT_FLODERS_VER,
DM_LSTUPDDT,
DM_BTNUMBER,
DM_USERID,
DM_WSID,
STAT_FLG,
SERVICES_FLG,
SERVICES,
INTRST_COND,
PST_INSTRN
FROM &&SRC.ACCOUNT_FOLDERS, &&SRC.DB
WHERE (POS_TYPE, POS_ID, SUB_ACNT_ID) IN (SELECT POS_TYPE, POS_ID, SUB_ACNT_ID
FROM ACCOUNT
WHERE DM_LSTUPDDT > 1_LAST_RUN_DATE
OR 1_FIRST_RUN_FLAG = 1); G. -
Help with WITH clause (ORA-24374: define not done before fetch or execute)
Hi all
I am uising with clause in SQL and getting this error. Please help ORA-24374: define not done before fetch or execute and fetch
with dea as
(SELECT MAX (idnt_value_cd) dea_num_cd,
MAX (xtl_bpa_idnt_value_eff_dt)dea_eff_dt,
MAX (idnt_value_cd_term_dt)dea_exp_dt,bpa_id
FROM xtl_bpa_idnt_value
WHERE xtl_bpa_idnt_id = 1
AND merci_util.is_date_range_active
(xtl_bpa_idnt_value_eff_dt,
idnt_value_cd_term_dt
) = 0
GROUP BY bpa_id)
SELECT 'IPLAN' src_sys_name, bp.bp_id src_bp_id, 'INDV' bp_type_cd,
CAST (NULL AS VARCHAR2 (10)) src_bp_clsfn_cd,
CAST (NULL AS VARCHAR2 (10)) src_bp_sub_clsfn_cd,
CAST (NULL AS VARCHAR2 (100)) bp_name, hcp.first_nm first_nm,
hcp.middle_nm midl_nm, hcp.last_nm last_nm,
hcp.name_pfx_dcd salu_txt, hcp.name_sufx_dcd sfx_txt,
birth_yr_cd || birth_mth_cd || birth_day_cd birth_dt,
gender_dcd gndr_cd, mpro_type.mpro_cd src_pfsnl_dgntn_cd,
(SELECT spty_nm
FROM specialty
WHERE spty_id =
(SELECT spty_id
FROM bp_specialty
WHERE bp_id = bp.bp_id
AND bp_specialty_id =
(SELECT MAX (bp_specialty_id)
FROM bp_specialty
WHERE bp_id = bp.bp_id)))
src_prim_mdcl_spty_cd,
(SELECT spty_nm
FROM specialty
WHERE spty_id =
(SELECT spty_id
FROM bp_specialty
WHERE bp_id = bp.bp_id
AND bp_specialty_id =
(SELECT MAX (bp_specialty_id) - 1
FROM bp_specialty
WHERE bp_id = bp.bp_id)))
src_sec_mdcl_spty_cd,
(SELECT spty_nm
FROM specialty
WHERE spty_id =
(SELECT spty_id
FROM bp_specialty
WHERE bp_id = bp.bp_id
AND bp_specialty_id =
(SELECT MAX (bp_specialty_id) - 2
FROM bp_specialty
WHERE bp_id = bp.bp_id)))
src_tert_mdcl_spty_cd,
lic.lic_num_cd src_st_lic_num, vhcp.state_cd src_sln_state_cd,
lic.lic_eff_dt src_st_lic_eff_dt,
lic.lic_expr_dt src_st_lic_exprn_dt,
bp_status.bp_status_type_dcd src_bp_actv_ind,
bp_status.bp_status_eff_dt src_bp_sta_chg_dt,
mpro_type.mpro_type_dcd titl_txt,
CAST (NULL AS VARCHAR2 (10)) src_cmeh_bp_id,
(SELECT xtl_bp_idnt_value_cd
FROM xtl_bp_idnt_value
WHERE bp_id = vhcp.hcp_id AND xtl_bp_idnt_id = 6)
callmax_cust_id,
CAST (NULL AS VARCHAR2 (10)) wk_num,
(SELECT xtl_bp_idnt_value_cd
FROM xtl_bp_idnt_value
WHERE bp_id = vhcp.hcp_id AND xtl_bp_idnt_id = 26) ims_psbr_num,
(SELECT xtl_bp_idnt_value_cd
FROM xtl_bp_idnt_value
WHERE bp_id = vhcp.hcp_id AND xtl_bp_idnt_id = 22) ama_num,
(SELECT xtl_bp_idnt_value_cd
FROM xtl_bp_idnt_value
WHERE bp_id = vhcp.hcp_id AND xtl_bp_idnt_id = 3) aoa_num,
(SELECT xtl_bp_idnt_value_cd
FROM xtl_bp_idnt_value
WHERE bp_id = vhcp.hcp_id AND xtl_bp_idnt_id = 21) ada_num,
CAST (NULL AS VARCHAR2 (10)) vet_num,
(SELECT xtl_bp_idnt_value_cd
FROM xtl_bp_idnt_value
WHERE bp_id = vhcp.hcp_id AND xtl_bp_idnt_id = 23) np_num,
(SELECT xtl_bp_idnt_value_cd
FROM xtl_bp_idnt_value
WHERE bp_id = vhcp.hcp_id AND xtl_bp_idnt_id = 20) pa_num,
CAST (NULL AS VARCHAR2 (10)) pod_num,
CAST (NULL AS VARCHAR2 (10)) opt_num,
(SELECT xtl_bp_idnt_value_cd
FROM xtl_bp_idnt_value
WHERE bp_id = vhcp.hcp_id AND xtl_bp_idnt_id = 7) tax_id,
CAST (NULL AS VARCHAR2 (10)) hin_num,
CAST (NULL AS VARCHAR2 (10)) npi_num,
vhcp.phone_num_cd bp_off_phn_num, vhcp.fax_num_cd bp_fax_num,
CAST (NULL AS VARCHAR2 (10)) bp_cell_phn_num,
CAST (NULL AS VARCHAR2 (10)) bp_pager_num,
CAST (NULL AS VARCHAR2 (10)) bp_home_phn_num,
CAST (NULL AS VARCHAR2 (10)) bp_vmail_num,
vhcp.e_mail_cd bp_email_addr_txt,
CAST (NULL AS VARCHAR2 (10)) bp_url, vhcp.bpa_id src_bpa_id,
vhcp.addr_1_ds addr_ln_1_txt, addr_2_ds addr_ln_2_txt,
CAST (NULL AS VARCHAR2 (10)) addr_ln_3_txt,
CAST (NULL AS VARCHAR2 (10)) addr_ln_4_txt, city_nm,
state_nm state_cd, postal_cd zip_5,
CAST (NULL AS VARCHAR2 (10)) zip_4,
vhcp.pfrd_ctac_loc_ind pfr_locn_ind,
DECODE
(merci_util.is_date_range_active ((SELECT bp_address.eff_dt
FROM bp_address
WHERE bpa_id = vhcp.bpa_id),
(SELECT bp_address.end_dt
FROM bp_address
WHERE bpa_id = vhcp.bpa_id)
0, 'ACTIVE',
'INACTIVE'
) src_bpa_actv_ind,
TO_CHAR (vhcp.bpa_updt_dtm, ' YYYYMMDD') src_bpa_sta_chg_dt,
vhcp.prac_loc_ind bpa_off_addr_ind,
vhcp.ship_to_loc_ind bpa_ship_addr_ind,
vhcp.pfrd_fncl_loc_ind bpa_bill_addr_ind,
(SELECT bp_address.mail_loc_ind
FROM bp_address
WHERE bpa_id = vhcp.bpa_id) bpa_mail_addr_ind,
CAST (NULL AS VARCHAR2 (10)) bpa_sm_addr_ind,
(SELECT bp_address.home_loc_ind
FROM bp_address
WHERE bpa_id = vhcp.bpa_id) bpa_home_addr_ind,
CAST (NULL AS VARCHAR2 (10)) bpa_hdqtr_addr_ind,
vhcp.affiliation_ind bpa_affl_addr_ind,
CAST (NULL AS VARCHAR2 (10)) bpa_prov_addr_ind,
CAST (NULL AS VARCHAR2 (10)) bpa_other_addr_ind,
dea.dea_num_cd,
dea.dea_eff_dt,
dea.dea_exp_dt,
CAST (NULL AS VARCHAR2 (10)) schd_clas_cd,
(SELECT MAX (idnt_value_cd) affl_id_cd
FROM xtl_bpa_idnt_value
WHERE 1 = 1
AND xtl_bpa_idnt_id = 3
AND merci_util.is_date_range_active
(xtl_bpa_idnt_value_eff_dt,
idnt_value_cd_term_dt
) = 0
AND xtl_bpa_idnt_value.bpa_id = vhcp.bpa_id
GROUP BY bpa_id) ims_outlet_num,
(SELECT MAX (idnt_value_cd) affl_id_cd
FROM xtl_bpa_idnt_value
WHERE 1 = 1
AND xtl_bpa_idnt_id = 6
AND merci_util.is_date_range_active
(xtl_bpa_idnt_value_eff_dt,
idnt_value_cd_term_dt
) = 0
AND xtl_bpa_idnt_value.bpa_id = vhcp.bpa_id
GROUP BY bpa_id) callmax_afln_id,
CAST (NULL AS VARCHAR2 (10)) src_cmeh_bpa_id,
vhcp.bpa_id src_addr_id, vhcp.phone_num_cd bpa_off_num,
vhcp.fax_num_cd bpa_fax_num,
CAST (NULL AS VARCHAR2 (10)) bpa_cell_phn_num,
CAST (NULL AS VARCHAR2 (10)) bpa_pager_num,
CAST (NULL AS VARCHAR2 (10)) bpa_home_phn_num,
CAST (NULL AS VARCHAR2 (10)) bpa_vmail_num,
vhcp.e_mail_cd bpa_email_addr_txt,
CAST (NULL AS VARCHAR2 (10)) bpa_url,
CAST (NULL AS VARCHAR2 (10)) bp_filler_1,
CAST (NULL AS VARCHAR2 (10)) bp_filler_2,
CAST (NULL AS VARCHAR2 (10)) bp_filler_3,
CAST (NULL AS VARCHAR2 (10)) bp_filler_4,
CAST (NULL AS VARCHAR2 (10)) bp_filler_5,
CAST (NULL AS VARCHAR2 (10)) bpa_filler_1,
CAST (NULL AS VARCHAR2 (10)) bpa_filler_2,
CAST (NULL AS VARCHAR2 (10)) bpa_filler_3,
CAST (NULL AS VARCHAR2 (10)) bpa_filler_4,
CAST (NULL AS VARCHAR2 (10)) bpa_filler_5,
max_date (max_date (vhcp.bpa_updt_dtm, vhcp.hcp_updt_dtm),
bp_status.updt_dtm
) updt_dtm,
SYSDATE refresh_dtm
FROM business_party bp,
hcp,
(SELECT hcp_id, lic_num_cd, MIN (lic_eff_dt) lic_eff_dt,
MAX (lic_expr_dt) lic_expr_dt
FROM mpro_govt_org_license
WHERE 1 = 1
AND merci_util.is_date_range_active (lic_eff_dt, lic_expr_dt) =
0
GROUP BY hcp_id, mpro_type_dcd, geoa_id, lic_num_cd) lic,
(SELECT code_type_nm, code_value_cd mpro_type_dcd,
xtl_src_obj_cd mpro_cd
FROM xtl_src_code_value
WHERE 1 = 1 AND code_type_nm = 'MPRO_TYPE') mpro_type,
vm_hcp_address vhcp,
bp_status,
dea
WHERE bp.bp_id = hcp.hcp_id
AND hcp.hcp_id = lic.hcp_id(+)
AND dea.bpa_id(+) = vhcp.bpa_id
AND bp.hcp_ind = 'Y'
AND hcp.mpro_type_1_dcd = mpro_type.mpro_type_dcd(+)
AND hcp.hcp_id = vhcp.hcp_id
AND hcp.srch_ctac_bpa_id = vhcp.bpa_id
AND hcp.hcp_id = bp_status.bp_id
and hcp.hcp_id=2200970Do you have an Oracle version? Trick question, you do, we just have no idea what it is.
select * from v$version;Also, do you have a line number where this error occurs? Another trick question, you do, but you haven't posted it :(
And finally, what are you using to run this query (SQLPLUS, SQLDEVELOPER, TOAD, etc....).
And finally finally, please use the code tags .... { code } with no spaces so that your code doesn't look like a dictionary vomiting.
Thanks.
Maybe you are looking for
-
File sender adapter is not working
Hello All, We are facing a problems with file sender adapter. Communication channel is not picking the files from the directory, but the status in RWB for that channel is 'Functioning'. We are not sure whether the channel is locked or any other probl
-
AirPort refuses to be detected.
Earlier today i was playing around with AirPort settings to try to get my PSP to work with it. Now all of sudden my AirPort Express cannot be found by my iMac and im going crazy looking for the option to set up a new network. AirPort Seup Assistant c
-
I am unable to access my Amercian Express online Account?
Windows XP Pro 2002, service pack 3 Firefox v20.0.1 Two days ago, I found myself unable to access my American Express on-line account, with Firefox. As I attempt to login and I am unable to connect to https://online.amercianexpress.com... I have succ
-
Don't have access to my old apps and I can't remember how to call fields from a database link now... when i try select "TABLE"."DATE" as "Date" from "TABLE" "TABLE" @LINKNAME I get ORA-00933: SQL command not properly ended Tried CHRISD which is the n
-
Help,how to display a index in report
Dear all experts,i need to modify the following code so tat i can actually dispaly one more columm which is at pos0 for the index number. i add in the following code in bold,but it din give me any display... IF WA_MVSTAT-MATNR EQ SPACE. AT N