How to construct a SQL for this logic.
Hi,
I have a requirement like, i need to derive a column with a calculation.
Here is the psedocode,
count of occurance (deptno=10)/count (deptno=10)
Desired result:
If the deptno =10 occurs 3 times in the table then at the fist time the calcuation should be,
1/3, second time 2/3, third time 3/3 and so on.
How can i construct this in a sql query. Please help.
Any help will be appreciated with points.
Thanks.
WITH DATA AS
(SELECT DEPTNO,
ROW_NUMBER() OVER(PARTITION BY DEPTNO ORDER BY DEPTNO) RN,
COUNT(DEPTNO) OVER(PARTITION BY DEPTNO ORDER BY DEPTNO) CNTDEPTNO
FROM SCOTT.EMP)
SELECT DEPTNO, RN, CNTDEPTNO, TO_CHAR(RN)||'/'||TO_CHAR(CNTDEPTNO) AS CNT
, RN/CNTDEPTNO AS calcl
FROM DATAyou want this?
Edited by: Mahir M. Quluzade on Mar 10, 2011 10:59 AM
Similar Messages
-
How to construct a formula for this logic.
Hi,
I have a requirement like, i need to derive a column with a calculation.
Here is the psedocode,
count of occurance (deptno=10)/count (deptno=10)
Desired result:
If the deptno =10 occurs 3 times in the table then at the fist time the calcuation should be,
1/3, second time 2/3, third time 3/3 and so on.
How can i construct this in a formula/report/rpd design. Please help.
Any help will be appreciated with points.
Thanks.The running aggregate will help you do this, i.e. RCOUNT, RSUM
This should work:
RSUM( CASE WHEN deptno = 10 THEN 1 ELSE 0 END )
to give you the running count of the rows where deptno = 10
Then you can divide ths by
SUM( CASE WHEN deptno = 10 THEN 1 ELSE 0 END )
not sure if that will work 100% or not but try the first statement so you can see the running aggregate working, then try the division to see if it works:
RSUM( CASE WHEN deptno = 10 THEN 1 ELSE 0 END ) / SUM( CASE WHEN deptno = 10 THEN 1 ELSE 0 END ) -
How to write complex sql for this
Hi ALL,
I have a requirement like this
I have 5 tables which i have to join to get the result
but there no join column to 2 other table.
I want to get all the applications using cobal,running on UNIX.
How to write the query for this
1.APP
APP_i DESC
1 Accounts
2 Payments
3 order transfer
4 Order processing
2.Techgy
techid techdesc
1 cobal
2 Java
3.APP_Techgy
APP_I Techid
1 1
2 1
3 1
4 2
4.Pltfrm
pltfmid pltfrmdesc
1 Windows NT
2 UNIX
5.APP_Pltfrm
APP_I pltfrmid
1 1
2 1
3 2
4 2
ouput must be
APP_i Desc techDESC pltfrmdesc
3 ordertranfer Cobal UNIX
Thanks in advanceThis ('descr' in place of 'desc')?
SQL> select a.app_i, a.descr, t.techdesc, p.pltfrmdesc
from app_techgy atc,
app a,
techgy t,
app_pltfrm ap,
pltfrm p
where atc.techid = t.techid
and atc.app_i = a.app_i
and atc.app_i = ap.app_i
and ap.pltfrmid = p.pltfmid
order by a.app_i
APP_I DESCR TECHDESC PLTFRMDESC
1 accounts cobal windows nt
2 payments cobal windows nt
3 order transfer cobal unix
4 order processing java unix
4 rows selected. -
How to correct the sql for this
Here is my requirement
How to find the master apps for this.
If there is rollup info for a app then it is parent
Rollup info is present in table B with flag R
Table A
AppNo Name
1 abc
2 xyz
3 pqr
4 mno
5 stu
6 ccc
7 ddd
Table B
srce dpnt flag
1 1 R
2 6 R
2 7 R
3 4 R
So now the parent apps are 1,2,3 since they have children (1,6,7,4)
Now i want 5 to be included in the parent list as it is an independent app
Appno name
1 abc
2 xyz
3 pqr
5 stu
my query is not including appno
appno name
5 stu
select * from TableA a
where a.appno in (
select distinct SRCE from TableB where b.SRCE=a.appno
and b.flag='R' )one solution:
select srce from table_b
union
select appno from table_a
minus
select dpnt from table_b
) -
Hi,
Below is my table with columns like a,b,c
a b c
1 null null
null 2 null
null null 3
I need output like a b c
1 2 3Hi,
Here's one way
SELECT MIN (a) AS a
, MIN (b) AS b
, MIN (c) AS c
FROM my_table;
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
Point out where the query above is giving the wrong results, and explain, using specific examples, how you get the correct results from the given data in those places. If you changed the query at all, post your code.Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002 -
How to write Dynamic SQL for this SQL ?
EXECUTE IMMEDIATE 'select COUNT(*) from dba_Tab_privs@' ||db_link|| ' WHERE Grantee <> 'DELETE_CATALOG_ROLE'
AND Table_Name = 'LINK$'
AND Grantee NOT IN (SELECT Grantee
FROM dba_Role_privs
WHERE Granted_Role = 'DBA')' into i using x;Hi bapalu,
I take that x is the name of your db_link?
If so,
DECLARE
i NUMBER;
x dba_db_links.db_link%TYPE;
stmt VARCHAR2(255);
BEGIN
x := 'some_link';
stmt :=
'SELECT count(*)
FROM dba_tab_privs@:db_link
WHERE grantee <> ''DELETE_CATALOG_ROLE''
AND table_name = ''LINK$''
AND grantee NOT IN(SELECT grantee
FROM dba_role_privs
WHERE granted_role = ''DBA'')';
EXECUTE IMMEDIATE REPLACE(stmt, ':db_link', x)
INTO i;
dbms_output.put_line('The count: ' || i);
END;Also, I think this is maybe not what you want:
AND table_name = ''LINK$''Regards
Peter -
Internal Error - Unable to generate SQL for this Scheduled Workbook
I am encountering the following error when loading the results of a Scheduled Workbook;
Internal Error - Unable to generate SQL for this Scheduled Workbook (If you scheduled this workbook using a previous version of Discoverer, please reschedule and re-open)
This only happens for one of the scheduled workbooks and I am struggling to find an explanation to the problem. There are no reference to database links in the workbook so I can rule that out as a cause.
Does anyone have any suggestions to what might be causing the problem?
Many thanks
StewartHi,
The version is OracleBI Discoverer Plus Version 10.1.2.48.18. Do you think this has anything to do with it?If you are on this version, then you have the recommended patches applied.
Did you try to reschedule the workbook and see if this helps in resolving the issue?
I would suggest you enable server logging as this may help in collecting more details about the error.
Note: 403689.1 - How To Generate Discoverer 10g (10.1.2) Session Server Logs In Text Format
https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=403689.1
Regards,
Hussein -
Require a Message mapping for this Logic.
Hi Experts,
I require a Message mapping for this Logic.
In the Source there are 4 fields and, the Target side, the fields should appear like this.
Source Structure- File
Record
|-> Header
Order_No
Date
|-> Item
Mat_No
Quantity
Target Structure-IDoc
IDoc
|-> Header
|-> Segment
Delivery_Order_No
Recv_Date
|-> Item
|-> Segment
Delivery_Order_No
Material_Num
Recv_Quantity.
The Logic is for every Order number an IDOC is generated.And if the Material num matches then the quantity should be added. and important note is that the material numbers are different for every order number. That means if a material number is 2 in the order number A. Then the material number can never be 2 in any of the order numbers.Here is the following with an example for the above scenario.
For example:-
we have
Source Structure- File
Order-no Date Mat_No Quantity
1 01/02/2011 A 10
1 01/02/2011 B 15
1 01/02/2011 A 10
2 01/02/2011 C 10
2 01/02/2011 C 10
3 01/02/2011 D 20
3 01/02/2011 D 10
3 01/02/2011 E 25
Target Structure-IDoc
Delivery_Order_No Recv_Date Material_Num Recv_Quantity
1 01/02/2011 A 20
1 01/02/2011 B 15
2 01/02/2011 C 20
3 01/02/2011 D 30
3 01/02/2011 E 25
So for this example total of 5-Idocs created. That means for this example if Order_No is 1 When the Mat_No is A the quantity gets added. For this Scenario 1 IDoc with four Fields 2 in Header(Delivery_Order_No, Recv_Date) and 2 in Item(Material_Num, Recv_Quantity) is generated by adding the quantity field in the Target Side. Similarly if Order_No is 1 when the Mat_No is B then separate IDoc is generated with four Fields 2 in Header(Delivery_Order_No, Recv_Date) and 2 in Item(Material_Num, Recv_Quantity) in the Target Side. Similarly, if Order_No is 2 when the Mat_No is C, an IDoc is generated with four Fields 2 in Header(Delivery_Order_No, Recv_Date) and 2 in Item(Material_Num, Recv_Quantity) by adding the quantity field in the Target Side. ike wise the process goes on upto 3.Kindly do the needy..
Thanq very much in advance..
Edited by: Prashanth Bharadwaj on Oct 17, 2011 1:29 PMHi Prashanth,
Concatinate the two fields OrderNo and MaterialNo and follow the below logic which will resolve your problem.
concatinationOfOrderNo&MaterialNo>removecontext>sort>splitByValueChange>collapseContext-->IDOC
concatinationOfOrderNo&MaterialNo>removecontext>sort>splitByValueChange>collapseContext>splitByEachValue>subString(0,1)-->Delivery_Order_No
formatByExample>collapseContext>SplitByEachValue-->Recv_Date
FormatByExample:
input1:resulrOfSortByKey
input2:concatination>removecontext>sort-->SplitByValuChange
sortByKey:
input1:concatination-->removecontext
input2:date-->removecontext
concatinationOfOrderNo&MaterialNo>removecontext>sort>splitByValueChange>collapseContext>splitByEachValue>subString(1,1)-->Material_Num
formatByExample>sum>Recv_Quantity
FormatByExample:
input1:sortByKey
input2:concatination>removecontext>sort-->SplitByValueChange
SortByKey:
input1:concatination-->removecontext
input2:Quantity-->removeContext
Regards,
Priyanka. -
How to create a hirarchy for this characteristic having lengh 50?
Hi guru's
I have a scenario like characteristic is having lengh 50.Now I want to create a hierarchy for this characteristic.
But Hirarchy allows maximum lengh 32chrs only.
So could you please let me know how to create a hirarchy for this characteristic having lengh 50?
Thanks in advance
SivanandIsn't this the same question as here:
Hi all, Have a problem, Please let me know urgently.
Why the duplicate postings with different names?? -
Arabic is not listed as a display language in iTunes for Windows 7. How can I add support for this language?
Edit ---> referance -----> general ------> language
-
How to write Select statement for this codition
I need to check whether SGTXT contains BELNR value.
SGTXT is a text field and It should be matched with BELNR
How to write select statement for this.
Select AUGBL AUGDT into t_BSAD
from BSAD
where SGTXT should have the given BELNR Value.
Plz note : Here I cannot give as SGTXT = BELNR as coz BELNR have only 10 digits.Hi,
data temp(12).
concatenate '%' belnr '%' into temp.
Select AUGBL AUGDT into t_BSAD
from BSAD
where SGTXT like temp.
If belnr is having multiple values,just create a internal table as follows.
types : begin of ty,
belnr....
temp(12),
end of ty.
data itab_ type standard table of ty.
data wa type ty.
loop at itab into wa.
concatenate '%' wa-belnr '%' into wa-temp.
modify itab from wa index sy-tabix transporting temp.
endloop.
Change your select statement accordingly.
Kindly reward poits if it helps. -
Is it possible to share my calendar with all my subscription? If so How can i find URL for this?
Hi yilmazfromlondon,
The resource below explains how to share your iCloud calendars publicly. Is this what you are asking about?
iCloud: Share a calendar with others
http://support.apple.com/kb/PH2690
iCloud: Share a calendar with others
You can share a calendar both publicly and privately with other people. For specifics about viewing and editing privileges for shared calendars, and how participants can access the calendars, see Calendar sharing overview.
Share a calendar privately
Click the Share button to the right of the calendar name in the sidebar, then select Private Calendar.
Note: You can also share the same calendar publicly. For instructions, see the next task, “Share a calendar publicly.”
Type the invitee’s email address in the Add Person field and press Return.
Click the pop-up menu with the invitee’s name and choose access privileges (View & Edit or View Only).
For each person you want to share the calendar with, repeat steps 2 and 3.
When you’ve invited everyone and set their privileges, click OK.
Invitation emails are sent from your iCloud email address to the participants you specified.
Share a calendar publicly
Click the Share button to the right of the calendar you want to share, then select Public Calendar.
Note: You can also share the same calendar privately. For instructions, see the previous task, “Share a calendar privately.”
To invite people to view the calendar, click Email Link.
Type one or more email addresses in the To field, then click Send.
The people you specify automatically receive an invitation email that includes the calendar’s URL. An invitee doesn’t need to be an iCloud user to accept an invitation to view a shared public calendar.
In the sidebar, a shared calendar has a dark Share button.
You can also resend invitations to one or more invited participants at any time.
Last Modified: Feb 5, 2015
Cheers,
Judy -
How to write a PCR for this ?
Hi SAP-HR Experts .
Dear friends , My Company Requires a specific requiremnt that at the date of any Employee's
B'day his one day salary should get doubled and he is entitled to get one leave on his B'day .
I do not know how to write a PCR for this ?
May some Body tell me how to meet this requirement Please .
tell me please step by step how to go through ...
It will be great help for me .
Best regards : rajneeeshI think you can make it with something like this:
Write a PCR in schema, you can call the rule with "actio";
000860 ACTIO 9BIR AR Birthday
Rule 9BIR
9BIR Rule for Birthday
NUM=FG C Set " F (fixed indicator for deadline calculation); G (Birth date from infotype 0002);C (complete months)
NUM/12 División " Number of completed months divided by 12
NUMV0O2L Off.Lng en arg.var. " the last two places of the number are entered in the variable argument.
" if the rest is not 00, there is nothing to do
00 " if the rest is 00
ZERO= N AmtNumRteZeit = 0 "
AMT= 1002 Set " wagetype of salary
AMT/TKDIVI División " divides the amount by Partial Period Parameter Whole Month
ADDWTI1002 Input table " accumulates into 1002
Example: an employee with birthday 01.01.1977 in IT0002
Payrroll in january 08
wagetype 1002 before rule 9BIR:
3 1002 Salario Bas01 30,33 30,00 909,90
Rule 9BIR
NUM=FG C Set; NUM= 372
NUM/12 ; 372/12= 31 rest=00
AMT=1002 ; AMT= 909,90
AMT/TKDIVI ; 909,90/31= 29,35
ADDWTI1002 ; 909,90 + 29,35= 939,25
wagetype 1002 before rule 9BIR:
3 1002 Salario Bas01 30,33 30,00 939,25
Hope this helps. Manuel -
How to make jar file for this compilation method ?
can any one tell me how to make jar file for this compilation
D:\java\browser\IEInJava>javac -classpath jdic.jar;. IEInJava.java
D:\java\browser\IEInJava>java -cp jdic.jar;. IEInJava
*this is a compile code:-*
D:\java\browser\IEInJava>javac -classpath jdic.jar;. IEInJava.java
*and this is a run code:-*
D:\java\browser\IEInJava>java -cp jdic.jar;. IEInJavanow how make JAR file ?Assuming IEInJava only uses classes inside the jdic jar, this is one way. D:\java\browser\IEInJava> jar cf yourjar.jar IEInJava.classThen to run it you would use D:\java\browser\IEInJava> java -cp jdic.jar;yourjar.jar IEInJavaAnother way would use the jar manifest file to specify the Main-Class and Class-Path.
-
HT4623 i have iOS 4.2.1 in 3G old one. how to get the applications for this iOS
i have iOS 4.2.1 in 3G old one. how to get the applications for this iOS
look at this thread
https://discussions.apple.com/message/22837309#22837309
Maybe you are looking for
-
Sudden dramatic loss of TM remaining storage i.e. sudden increase in backup
Over the months, the amount remaining on my 1 Terabyte HD has been gradually decreasing, as Time Machine does backups. Today, I noticed a sudden, dramatic decrease in the amount of remaining storage. It dropped from around 400Gig to 360 Gig. That's a
-
How to call click event to HorizontalList item after it's been initialized
How do I to call the click event of a HorizontalList item after the dataprovider property of the HorizontalList object's been set and the first item's been created. I need to call it's click event.
-
Keyboard frozen or not working since downloading the new software..
please help, the keyboard not working or frozen,, there is a capital letter button,which has a red light.when you want capital letters , you press on that button.. i try to press on it, but the light is not coming up, red light.. so it means the keyb
-
Use of Scrollbar for movieclips
I have created a script that duplicates movieclip in an other movieclip with instance "mainmovie_mc" the problem is just that mostly the clip becomes bigger then the stage can some please give me a script or tell me how to create one that checks the
-
No backlight randomly on MacBookPro 5.1
Hi, I own a MBP 5,1 (late 2008) and I only use the 9400M graphic processor (never tried with the 96000 GT)... after upgrading to 10.6.3 I've noticed that randomly the screen doesn't light after hibernate. The only way to get it work is to hibernate i