How to break a ranked query into subcomponenets using analytics.
HI,
I'm using Oracle 10.2.0.4. I have a query where I'm listing the top X clients ranked by Total Margin.
The query in SQL looks like this.
Select
accounting_date,
customer_number,
customer_id,
customer_name,
TOT_PROD,
TOT_SVS,
TOT_MGN,
RANK_IN_LINE
from(
Select
RNK.accounting_date,
RNK.customer_number,
RNK.customer_id,
RNK.customer_name,
SUM (RNK.total_prod_margin) TOT_PROD,
SUM (RNK.total_svcs_margin) TOT_SVS,
SUM (RNK.total_margin) TOT_MGN,
RANK() OVER( ORDER BY SUM (RNK.total_margin) desc) RANK_IN_LINE
from
SELECT MGN.accounting_date,
MGN.customer_number,
MGN.customer_id,
MGN.customer_name,
SUM (MGN.prod_margin) total_prod_margin,
SUM (MGN.svcs_margin) total_svcs_margin,
SUM (MGN.prod_margin + MGN.svcs_margin) total_margin
FROM
(( SELECT TRUNC (ba.accounting_date) accounting_date,
ba.CUSTOMER_ACCOUNT_NUMBER customer_number,
to_char(nvl(ba.customer_id, -1)) customer_id,
ba.customer_name,
SUM (ba.book_margin_amount) prod_margin,
0 svcs_margin
FROM ftbv.ftbv_booking_activity_all_1d ba
WHERE ba.order_type_name <> 'Wholesale'
AND ba.SALESREP_NAME <> 'NO SALES CREDIT'
AND ba.product_group_name <> 'BAS New'
AND BA.PARTIAL_ID <> -1
GROUP BY TRUNC (ba.accounting_date),
ba.customer_account_number,
to_char(nvl(ba.customer_id, -1)),
ba.customer_name
HAVING SUM (ba.book_margin_amount) <> 0)
UNION ALL
( SELECT TRUNC (bs.accounting_date) accounting_date,
bs.AMS_CUSTOMER_NUMBER customer_number,
bs.CUSTOMER_ACCOUNT_NUMBER customer_id,
bs.customer_name,
0 prod_margin,
SUM (bs.book_gross_profit_margin_amt) svcs_margin
FROM ftbv.ftbv_book_svc_activity_all_1d bs
WHERE bs.booking_activity_name != 'Undefined'
GROUP BY TRUNC (bs.accounting_date),
bs.ams_customer_number,
bs.CUSTOMER_ACCOUNT_NUMBER,
bs.customer_name
HAVING SUM (bs.book_gross_profit_margin_amt) <> 0)) MGN
GROUP BY MGN.accounting_date,
MGN.customer_number,
MGN.customer_id,
MGN.customer_name) RNK
Group by
RNK.accounting_date,
RNK.customer_number,
RNK.customer_id,
RNK.customer_name,
RNK.total_prod_margin,
RNK.total_svcs_margin,
RNK.total_margin
order by RNK.customer_name , RNK.accounting_date)
where RANK_IN_LINE <=10
order by rank_in_line asc; Now I need to add fields where this is broken out by REGION and LINE OF BUSINESS but I want to keep the same number of clients. If I use the same calculation, I get only the top ten CLIENT, REGION, LINE OF BUSINESS values( two extra fields). I don't get the original list of client , I just get the top X lines.
What do I need to do in order to Keep the same top ten or what ever clients and show those values broken down by their regions and Lines of business (LOBs)?
The new fields are shown in this query
SELECT MGN.accounting_date,
MGN.customer_number,
MGN.customer_id,
MGN.customer_name,
MGN.SALES_REGION_NAME,
MGN.DESCRIPTION,
SUM (MGN.prod_margin) total_prod_margin,
SUM (MGN.svcs_margin) total_svcs_margin,
SUM (MGN.prod_margin + MGN.svcs_margin) total_margin,
-- RANK() OVER(PARTITION BY MGN.customer_name ORDER BY SUM (MGN.prod_margin + MGN.svcs_margin) desc)
FROM
(( SELECT TRUNC (ba.accounting_date) accounting_date,
ba.CUSTOMER_ACCOUNT_NUMBER customer_number,
to_char(nvl(ba.customer_id, -1)) customer_id,
ba.customer_name,
TERR.SALES_REGION_NAME,
decode(LOB.SALES_CHANNEL_CODE, 'SUN','Oracle',
'EBASOL', 'BAS',
'NBASOL', 'BAS',
'X86', 'X86',
'PC','X86',
'IBM','IBM',
LOB.DESCRIPTION) DESCRIPTION,
SUM (ba.book_margin_amount) prod_margin,
0 svcs_margin
FROM ftbv.ftbv_booking_activity_all_1d ba,
FTBV_DIM_TERRITORY_1D TERR,
FORX_LINES_OF_BUSINESS LOB
WHERE ba.order_type_name <> 'Wholesale'
AND ba.SALESREP_NAME <> 'NO SALES CREDIT'
AND ba.product_group_name <> 'BAS New'
AND BA.PARTIAL_ID <> -1
AND ba.TERRITORY_ID = TERR.TERRITORY_ID
AND BA.PRODUCT_GROUP_CODE = LOB.CODE
GROUP BY TRUNC (ba.accounting_date),
ba.customer_account_number,
to_char(nvl(ba.customer_id, -1)),
ba.customer_name,
TERR.SALES_REGION_NAME,
decode(LOB.SALES_CHANNEL_CODE, 'SUN','Oracle',
'EBASOL', 'BAS',
'NBASOL', 'BAS',
'X86', 'X86',
'PC','X86',
'IBM','IBM',
LOB.DESCRIPTION)
HAVING SUM (ba.book_margin_amount) <> 0)
UNION ALL
( SELECT TRUNC (bs.accounting_date) accounting_date,
bs.AMS_CUSTOMER_NUMBER customer_number,
bs.CUSTOMER_ACCOUNT_NUMBER customer_id,
bs.customer_name,
TERR.SALES_REGION_NAME,
'Service' DESCRIPTION,
0 prod_margin,
SUM (bs.book_gross_profit_margin_amt) svcs_margin
FROM ftbv.ftbv_book_svc_activity_all_1d bs,
FTBV_DIM_TERRITORY_1D TERR
WHERE bs.booking_activity_name != 'Undefined'
AND bs.TERRITORY_ID = TERR.TERRITORY_ID
GROUP BY TRUNC (bs.accounting_date),
bs.ams_customer_number,
bs.CUSTOMER_ACCOUNT_NUMBER,
bs.customer_name,
TERR.SALES_REGION_NAME,
'Service'
HAVING SUM (bs.book_gross_profit_margin_amt) <> 0)) MGN
GROUP BY MGN.accounting_date,
MGN.customer_number,
MGN.customer_id,
MGN.customer_name,
MGN.SALES_REGION_NAME,
MGN.DESCRIPTION
order by MGN.customer_name , MGN.accounting_date;
Also My output from the original SQL looks like this:
Client Number Client Name Product GPM SUM Services GPM SUM Total GPM SUM
109087 Client 1 1822052.627 0 1822052.627
114386 Client 2 803616 0 803616
101390 Client 3 101339.26 2516 103855.26
102740 Client 4 50000 0 50000
104698 Client 48057.83 0 48057.83
100229 Client 6 39555.289 0 39555.2894
106902 Client 7 4148.73 0 4148.73
103565 Client 8 3016.19 0 3016.19
130322 Client 9 1892 0 1892
130241 Client 10 700 0 700For the second query I removed the Top N constant and got too large a list. I'm getting this.
Client Number Client Name Region Line of Business Product GPM SUM Services GPM SUM Total GPM SUM
109087 Client 1 Central Storage 11473.9 0 11473.9
109087 Client 1 Central Security 21690.727 0 21690.727
109087 Client 1 Central Network 1788888 0 1788888
120360 Client 2 Central X86 -189.76 0 -189.76
104134 Client 3 Central X86 -412.8 0 -412.8
104698 Client 4 Central X86 48057.83 0 48057.83
103565 Client 4 Central Storage 3016.19 0 3016.19
102740 Client 5 Central Storage 50000 0 50000
108702 Client 6 Central Sun 109.21 0 109.21
108702 Client 6 Central Storage -336 0 -336
110019 Client 7 Central Network 397.5 0 397.5
105096 Client 8 Central Security 198 0 198
130241 Client 9 Central Security 700 0 700
105588 Client 10 Central Sun -7742 0 -7742
106902 Client 11 Central Security 4148.73 0 4148.73
130322 Client 12 Central Network 1892 0 1892
101965 Client 13 Central X86 64.92 0 64.92
100229 Client 14 Central IBM 39555.29 0 39555.29
100229 Client 15 Central Hewlett Packard -0.0006 0 -0.0006
114386 Client 15 Central Storage 803616 0 803616
107554 Client 16 Central Sun -6155 0 -6155
104724 Client 17 Central Network 280.24 0 280.24
101390 Client 18 Central X86 91093.89 0 91093.89
101390 Client 18 Central Service 0 2516 2516
101390 Client 18 Central Network 10245.37 0 10245.37It's not keeping the original Top Ten Clients of course, It's giving me too many. What analytics do I need to use to Keep the Top Ten (x) clients, but then broken out by that client into their respective subgroups of Region and LOB(Line of Business)?
Similar Messages
-
How to break the PDF file into images?
How to break the PDF file into images? There should be settings in Photoshop CS 6 that imports PDF file and break it into images. I have a short instruction:
2. Open the file in Photoshop.
3. A new window should open to Import PDF. Click on images, not pages import pdf into Photoshop.doc
4. Select all the files shown (shift + click), Click O.K. Four files should open on your screen.
Was anybody successful with that?Whether this is available solely depends on the structure of the PDF and whether it actually contains whole images that can be extracted separately. Depending on whatgoing on in the PDF this may simply not be the case and the images have been tiled and split up in multiple "objects" whose appearance can only be retained by rasrerizing the whole page...
Mylenium -
How to Append two word documents into single using java
How to Append two word documents into single using java
we tried this but it's not append the one word document to other
source code:public class AppendTwoWordFiles {
public static void main(String []arg)throws IOException
FileInputStream fi=null;
FileOutputStream fo=null;
try {
System.out.println("Enter the source file name u want to append");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
File f1=new File(br.readLine().toString());
System.out.println("Enter the Destination file name ");
File f2=new File(br.readLine().toString());
fi = new FileInputStream(f1);
fo = new FileOutputStream(f2,true);
byte b[]=new byte[2];
while((fi.read(b))!=-1);
fo.write(b);
System.out.println("Successfully append the file");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
finally{
fi.close();
fo.close();
plz reply me quickly ,,,what can i followUse this code ..
and give the path of the both file like this.....
source file ---- C:/workspace/Practice/src/com/moksha/ws/test/practice.text
destination file ---- C:/workspace/City/src/com/moksha/ws/test/practice1.text
import java.io.*;
public class AppendTwoWordFiles {
public static void main(String[] arg) throws IOException {
FileInputStream fi = null;
FileOutputStream fo = null;
try {
System.out.println("Enter the source file name u want to append");
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
File f1 = new File(br.readLine().toString());
System.out.println("Enter the Destination file name ");
File f2 = new File(br.readLine().toString());
fi = new FileInputStream(f1);
fo = new FileOutputStream(f2, true);
byte b[] = new byte[2];
int len = 0;
while ((len = fi.read(b)) > 0) {
fo.write(b, 0, len);
System.out.println("Successfully append the file");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
fi.close();
fo.close();
} -
Any ideas how I can insert a pdf into word, using the insert object option. However the pdf i want to insert has text and lines annotated, but once inserted the comments don't appear???? any help would be greatly appreciated.
You will need to find a forum for MS Word since that is the software that you are trying to manipulate in this. If you think the processing/creation of the PDF plays a role then you should ask in the forum for the software that you are using to create the PDF.
This forum is for issue regarding downloading and installing Adobe trial products, so in any circumstance, your issue does not fit in this forum. -
How do I install (import) certificat into FireFox using commad line?
I can import certificat using certutil.exe in command line, but this certificat is available only in Internet Explorer.
I can import certyficat into FireFox using its GUI. I must import that certificat on more then 60 PCs.
Question is: how do I install (import) certificat into FireFox using commad line?HI ScanBit,
Thank you for your question, in order to import the certificate in the command line you will need these resources:
*[https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/tools/NSS_Tools_certutil]
If you have any other questions about this, we are happy to help. -
How do I get this query into Discoverer Plus
Hi all,
I have the following query:
SELECT h.hrs, NVL(Quantity, 0) Quantity
FROM (SELECT TRIM(to_char(LEVEL - 1, '00')) hrs
FROM dual
CONNECT BY LEVEL < 25) h
LEFT JOIN (SELECT TO_CHAR(event_date, 'HH24') AS during_hour,
COUNT(*) Quantity
FROM user_activity u
WHERE event_date BETWEEN
to_date('15-JUN-2010 14:00:00', 'DD-MON-YYYY HH24:MI:SS') AND
to_date('16-JUN-2010 13:59:59', 'DD-MON-YYYY HH24:MI:SS')
AND event = 'user.login'
GROUP BY TO_CHAR(event_date, 'HH24')) t
ON (h.hrs = t.during_hour)
ORDER BY h.hrs;
Which produces the number of actions performed (from an event table, user_activity) grouped by the hour of the day they occurred (including displaying hours that have zero records - this bit is important!). I want to be able to put this into Discoverer plus as a worksheet, but I'm having trouble trying to figure out how.
I was able to create a custom folder in Administrator for the select from DUAL, but I cannot link it to the user_activity table because there's no relationship between to two tables to create a join.
The user_activity table is:
USER_ID - VARCHAR2(8 CHAR)
EVENT_DATE - DATE
EVENT - VARCHAR2(100 CHAR)
The custom folder is this part of the SQL:
SELECT TRIM(to_char(LEVEL - 1, '00')) hrs FROM dual CONNECT BY LEVEL < 25
Any suggestions would be greatly appreciated.
Thanks.
Edited by: Cyntech on Aug 12, 2010 10:41 AMKK wrote:
hi,
In the custom folder we can join tables,but the thing is you said ther is no join between them.
I would suggest you to built this query into a view and use this view in the DUAL table by writing inline query or subquery what ever way.
This is the only possibility i can think off.
Hope it helps you.
By,
KKHi,
Thanks for the reply, though I'm not sure that I understand what you are suggesting.
Which query would you turn into a view? If you are referring to the select from dual, then how would the view be any different from the custom folder? You still would not be able to join it to user_activity as there are no common columns.
Edited by: Cyntech on Aug 12, 2010 2:49 PM -
How to break up a String into multiple array Strings?
How do I break up a string into a bunch of String arrays after the line ends.
For example,
JTextArea area = new JTextArea();
this is a string that i have entered in the area declared above
now here is another sting that is in the same string/text area
this is all being placed in one text field
Sting input = area.getText();
now how do I break that up into an array of strings after each line ends?Ok I tested it out and it works.
So for future refrence to those that come by the same problem I had:
To split up a string when using a textfield or textarea so that you can store seperate sections of the string based on sperate lines, using the following code:
String text = area.getText() ;
String[] lines = text.split("\n") ;
This will store the following
this is all one
entered string
into two arrays
Cheers{
Edited by: watwatacrazy on Oct 21, 2008 11:06 AM
Edited by: watwatacrazy on Oct 21, 2008 11:16 AM
Edited by: watwatacrazy on Oct 21, 2008 11:16 AM -
How to break the name column into first,middle,last
hi,
Having a column in a table called employee_name which is
containing the names of employees like:-
employee_name
Syed Azhar Husain
Also having another table having cloumns first_name,middle_name, last_name
I just want to write the query that break my employee_name column into
first name, middle name, last name and
store into table columns first_name, middle_name, last_name respectively
i.e. it should display like
first_name middle_name last_name
Syed Azhar husain
I am using oracle9i database.
Thanks in advance
AzharDear Asuri,
Thanks for quick reply,
your query was working fine when there was one record into the table but when there was more then one record into the table it was giving error "ORA-01427: single-row subquery returns more than one row". So i did small modification in the query as below
SELECT SUBSTR(' ' || name || ' ', INSTR(' ' || name || ' ' , ' ', 1, rn) +1,
INSTR(' ' || name || ' ' , ' ', 1, rn + 1) - INSTR(' ' || name || ' ' , ' ', 1, rn) -1) name
FROM test , (SELECT ROWNUM rn FROM all_objects
WHERE ROWNUM <= ( SELECT distinct(LENGTH(name) - (LENGTH(REPLACE(name, ' ')))) / LENGTH(' ') + 1
FROM test ))
order by name
so above query is working fine with more than one record but there is another problem as i am explaining blow
Suppose there is table called "test" as follows
SQL> select * from test;
NAME
Rajendra kumar jain
syed azhar husain
Chander Shekhar Kumar
when i am putting above query it is giving result as follows
NAME
Chander
Kumar
Rajendra
Shekhar
azhar
husain
jain
kumar
syed
my requirement is that for complete full name like 'syed azhar husain' it should give
name
fist name : syed
middle name: azhar
last name: husain
first name: rejendra
middle name: kumar
last name: jain
first name: chander
middle name: shekhar
last name: kumar -
How to save navigations of Query into Portal favorites?
Hi,
i executed a query in the portal. i made some changes by navigating, drag & drop options ( added new fields, displayed attributes, removed 1 field for example).
how to save this navigation into portal favorites? will it possible?
if i save my query into Federated portal favorites, user can able see those later. is that true?
thanks in advance.
Regards,
Nagesh Ganisetti.Hi Nagesh,
Can you please explain how did u solve this issue. I am also facing same issue?
Thanks and Regards
Satish Arra -
How to convert an sql query into a recordset?
HI, I'm having a hard time building a locations of service form for users to insert, update the cities, counties, zip codes based on the states selected.
so I found this query that works great if I use basic menus and text boxes, but can't use to make comma separated menus because it is nat a record set.
The problem is that I have a table called zip_codes, with the following fields: state_label, Zip_b, county, city.
zip codes correspond to the cities, counties and states.
example:
Colorado, Colorado Springs, El Paso, 80918
Users make a selection of state or states and the recordset is filtered by user selection.
I manage the part of making a select mutiple drop menu that passes the values to my query page like this.
<form action="litsTA.php"; method="post">
<h3>Choose State(s)</h3>
<p>hold Control key to select multiple states</p>
<select name="States_served[]_<?php echo $cnt1; ?>" multiple="multiple" onchange='showselection()'>
<?php
do {
?>
<option value="<?php echo $row_state['state_label']?>"><?php echo $row_state['state_label']?></option>
<?php
} while ($row_state = mysql_fetch_assoc($state));
$rows = mysql_num_rows($state);
if($rows > 0) {
mysql_data_seek($state, 0);
$row_state = mysql_fetch_assoc($state);
?>
</select>
<p>
<input type="submit" value="submit" />
</p>
</form>
And the query I need to convert into a recordset looks like this
mysql_select_db($database_duitop, $duitop);
$query_TONY = "SELECT * FROM zip_code WHERE state_label IN (";
for ($i=0; $i<=count($state_list)-1; $i++) {
//echo $state_list[$i];
$query_TONY = $query_TONY . "'" . $state_list[$i] . "'";
if ($i < count($state_list)-1) {
$query_TONY = $query_TONY . ", ";
$query_TONY = $query_TONY . ") GROUP BY county ORDER BY state_label, city ASC";
Any way that was my attempt to converting the query into a recordset.
any help, or samples will be appreciated.Use Tcode SQ01.
Give the query name press Enter.
The query will be listed in the table below.
Select the Query => From the Main menu select QUERY => More Functions => Display Report Name.
You will get the program name, now go to Se38 and display the program... -
ALV grid - how to break a long string into several lines?
I have a ALV grid, where one of the fields contains a textstring that is typically 100 characters long.
Is it possible to break this long string into shorter strings on multiple rows?
Kind of like in Excel, when using row break...Thats not possible in ALV
-
How to eliminate inserting Duplicate rows into database using JDBC Adapter
File->Xi->JDBC
In above Scenario if the file has two rows their values are identical, then how can we eliminated inserting Duplicate rows into database using JDBC AdapterDatabase is a consumer of a SERVICE (SOA!!!!!!).
Database plays a business system role here!!!!
Mapping is part of an ESB service
Adaptor is a technology adapted to ESB framework to support specific protocol.
ESB accomplish ESB duties such as transformation, translation, routing. Routing use a protocol accepted by the consumer. In a JDBC consumer it is JDBC protocol and hence it a JDBC adaptor.
There is clear separation on responsibilities among business system and ESB. ESB do not participate in business decision or try to get into business system data layer.
So who ever are asking people to check duplicate check as part of mapping (an ESB service) may not understand integration practice.
Please use an adaptor module which will execute the duplicate check with business system in a plug and play approach and separate that from ESB service so that people can build integration using AGILE approach.
Thanks -
How to load Essbase member formula into DRM using Automator
Hi,
I just wonder how to load Essbase member formula into a member property in DRM?
I encounter a problem when loading a member formula which as new line in the formula.
Here is the example of the record for Automator using | (pipe) delimiter where the formula has carriage return / new line:
ChangeProp|Master|Accounts|CYTDSignOnBonus|ESB_Formula|[OpenInputValueBlock]
[CYTD("Sign On Bonus")]
[CloseInputValueBlock]
In the above example. when the formula is loaded, it only load the 1st line and strip the remaining line.
Thanks.Hello,
I have encountered this issue as well and here is how I receommend you deal with it. Unfortunately, DRM does not understand multiple lines in a formula and so it truncates the other lines.
1. The best way around it is to ensure that your formula does not have multiple lines. Strip all the enters and only use spaces. Essbase does not care about aesthetics as long as the formula is all in one line. This should take care of it.
2. Sometimes, the formulas for member properties are very long and they are in multiple lines. You can try using excel formulas to bring them all in one line. After removing enters and tabs myself multiple times, I informed my Essbase developers of this DRM issue and told them to provide me with the formulas without using Enters and tabs.
Hope this helps.
-- Adi -
How to store Multiple Ec\xcels into Table Using sql loder
Plese guide me to store Multiple Ec\xcels into Table Using sql loder
I am not clear with your question. Do you want to load multipel Excel Files into a table. If so you can follow this link.
http://www.orafaq.com/wiki/SQL*Loader_FAQ#Can_one_load_data_from_multiple_files.2F_into_multiple_tables_at_once.3F
Thanks,
Karthick. -
How to write data from query into Real time cube?
Hi All,
Can anyone explain me step by step how to write data into a real time cube from front end queries.
Thanks in advanceHi
You can do this using Integrated Planning
You need to create a aggregation level on the Real Time infocube and can create Planning function/sequence, Variables if needed.
Then you can create query on this aggregation level and you can make the keyfigures Input ready in property pane and you can change the data and save it into cube.
Please find below help link which clearly explains step by step about Integrated Planning like creating input ready queries etc.,
http://help.sap.com/saphelp_nw70ehp1/helpdata/en/43/0c033316cd2bc4e10000000a114cbd/frameset.htm
Regards
Ravi
Maybe you are looking for
-
Different Posting Key for VF01
Hi, Can we assign a different posting key for Invoices/CMs posted via VF01? If yes how? can we assign posting key per document type?
-
Is color management in Motion causing me grief?
I'm stumped after looking through support docs and here in the forums, but I'm having problems getting correct color to come through on objects/layers. Here's my problem at a base level (it has other manifestations): 1. Add a color solid (solid1) set
-
Outlook 2013 Issues (Emails go missing when stucked in Outbox after restarted Outlook)
Hi, I have being using Outlook 2013 for email but i have face for two main issues as below which is quite annoy me sometime. 1. Email stucked at Outbox (even is just a normal email without attahcment). Those emails which were stucked at Outbox will g
-
I have not tried Flash CS3 but let’s just say “I Know”. I have been using Adobe products since the beginning! I’ve used Adobe products for illustration, photo work, and print media. I have been using formerly “Macromedia” products for the web since t
-
HT2534 I can't find the "None" Option in the payment option, what should I do?
I'm setting up my Apple ID to register it to App Store but as I continue to my Payment option, I can't find the "None" option. I don't have a credit card so I won't can't fill up the card number or something. How can I continue with this?