SQL & PL/SQL :: Rollup And Sorting
Jul 2, 2012
I have the following query
SQL>
SQL> SELECT DECODE(act.statement_flag, NULL, 'Total',act.statement_flag) "Monthly Statement?",
2 COUNT(account_id) "Count",
3 ROUND(((COUNT(account_id)/
(SELECT COUNT(account_id) FROM accounts
WHERE account_status_id = consts$.acct_sts_active))* 100),2) || '%' "Percent of Active Accounts"
4 FROM accounts act
5 WHERE act.account_status_id = consts$.ACCT_STS_active
6 GROUP BY ROLLUP(act.statement_flag)
SQL> /
Monthly Statement? Count Percent of Active Accounts
------------------ ---------- -----------------------------------------
N 1892 98.08%
Y 37 1.92%
Total 1929 100%
I want the output to be in the following fashion:
Monthly Statement? Count Percent of Active Accounts
------------------ ---------- -----------------------------------------
Y 37 1.92%
N 1892 98.08%
Total 1929
And I would also like to know is there another way to find the Percent of Active accounts in the query.
View 3 Replies
ADVERTISEMENT
May 22, 2011
difference between rollup and cube with simple example.
View 2 Replies
View Related
Aug 8, 2013
I am trying to use rollup for a total, but it doesn't work because what I'm totaling is too conditional. I even tried adding on the totals to the end using a union and a specialized function, but for some reason, the order by stops working when I do the union (all field aliases and types are the same).I know the structure of the query itself probably isn't the best, how I can get the grand total, The subtotals from the rollup work fine, though.
The order by query runs fine against both parts of the union when they are run individually, but once I make it part of the union - the first part of the order by is an unknown field and the second is not a SELECTed list expression. I've commented out the union here. The statement works fine without it except for the grand total being all 0s. I kind of understand why it's all 0s, but not how to get around that.This is running in Oracle 10g2. I am trying to get totals for decisions by each of the four component values: ex_land, ex_imp,tx_land,tx_imp and then subtotals for each component values.
That works for the following query, but I cannot get a grand total through the rollup.
CREATE TABLE "FL_APP" ( "APP_ID" NUMBER(*,0), "FL_STAT_CODE" VARCHAR2(20 BYTE), CONSTRAINT "FL_APP PK" PRIMARY KEY ("APP_ID") ENABLE, CONSTRAINT "FL_APP_FL_STAT_DIM_FK1" FOREIGN KEY ("FL_STAT_CODE") REFERENCES "FL"."FL_STAT_DIM" ("FL_STAT_CODE") ON DELETE CASCADE ENABLE ) ;CREATE TABLE "FL_APP_PROP" ( "APP_ID" NUMBER(*,0), "FL_DECISION_CODE" VARCHAR2(10
[code]....
View 8 Replies
View Related
Oct 18, 2010
I am trying to use decode funtion with GROUP BY ROLLUP.
MY query is working fine when i use this two queris individually
SELECT SUM(SAL),DEPTNO,JOB FROM EMP GROUP BY ROLLUP ((DEPTNO),(DEPTNO,JOB));
SELECT SUM(SAL),DEPTNO,JOB FROM EMP GROUP BY ROLLUP((JOB),(DEPTNO,JOB));
But when i use Decode funtion so that i can combine above two scenarios it is not working
SELECT SUM(SAL),DEPTNO,JOB FROM EMP GROUP BY ROLLUP ( DECODE(:A,'S',((DEPTNO),(DEPTNO,JOB) ),((JOB),(DEPTNO,JOB) ) ) )
View 3 Replies
View Related
Feb 7, 2013
I got the following data for which I will like to sort in ascending order.
B51-01-008/04022013/CRE1005/1
B51-01-008/04022013/CRE1005/2
B51-01-008/15-1-13/SSA6280/1
B51-01-008/31012013/CRE1005/1
B51-01-008/31012013/CRE1005/10
B51-01-008/31012013/CRE1005/2
and expected result will be
B51-01-008/15-1-13/SSA6280/1
B51-01-008/31012013/CRE1005/1
B51-01-008/31012013/CRE1005/2
B51-01-008/31012013/CRE1005/10
B51-01-008/04022013/CRE1005/1
B51-01-008/04022013/CRE1005/2
I will like to sort it based on the order on second segment for which is date, the earlier appear first then only the rest.
View 11 Replies
View Related
Jun 10, 2007
The db field is a string-type field that hold strings such as:
'1234'
'753'
'textstring'
'345'
Obviously, if you sort it, it'll be stored as a string such as:
'1234'
'345'
'753'
'textstring'
My client wants it so the numbers sort as integers, followed by string-like strings (sorted alphabetically), so it's like.
'345'
'753'
'1234'
'textstring'
Is there a quick and dirty SQL-only way to doing this in Oracle?
View 3 Replies
View Related
Jun 10, 2013
Is it possible to sort records based on hierarchy in such a way that records sorts in sequence and records of same level comes in the last (in sorting order)
Eg: Default hierarchy level order: 0,1,2,2,3,3,3,4,5
Above given is the default sorting order of an query for an parent 'NODE_A1' having multiple same level i.e 2 and 3
Expected Hierarchy level order: 0,1,2,3,4,5,2,3,3
Please check attached file for an example.
View 8 Replies
View Related
Mar 23, 2010
sort data set A,B,1,2,A1,A2,B1,B2,2B,1000 as A,B,1,2,1000,A1,A2,B1,B2,2B.
I tried with LPAD and EXPREG_REPLACE funtion. But it did not work.
View 13 Replies
View Related
Jun 18, 2010
I am trying to sort columns base on cluster and alpha numeric field.
Column1 Columns2 column3
1 2-CA6R-234 9
1 2-CA6R-231 8
1 ARCT-0037000000ewegZ 10
2 2-QIZFF7 1
3 2-PIZFF6 6
3 ARCT-0037000000ewipk 9
3 2-QIZTF7 1
Wanted to sort in a way that column1 will be same order and the second column will order first with ARCT-XXXXX and then reset of the column2. It should look like this
Column1 Columns2 column3
1 ARCT-0037000000ewegZ 10
1 2-CA6R-231 8
1 2-CA6R-234 9
2 2-QIZFF7 1
3 ARCT-0037000000ewipk 9
3 2-PIZFF6 6
3 2-QIZTF7 1
View 9 Replies
View Related
Sep 11, 2012
I'm trying to sort a collection in a nested table in PL/SQL so these value can be used later for a display and for export to Excel. The sort is failing.
-- PLS-00642: local collection not allowed in SQL statements
-- PL/SQl: ORA-00902: invalid datatype
The error message are also noted below in the code on the line that fails.
A quick overview of this code- Using a nested table MyNestedTable the values from several select queries are combined into MyRecordsetZero using CURSOR, and MULTISET UNION. I'm trying to either sort MyRecordsetZero or populate MyRecordsetSorted with the sorted values for futher use.
IMPORTANT: The code is running in an enviroment that does not have permission to create.
Versions:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Developer: 8.0.0.1480
DECLARE
-- Declare the variable MyTID to be used by select statements and
-- set its data type and max character count
MyTID varchar2(10);
[code]....
View 13 Replies
View Related
Nov 10, 2011
In test.pks file I declared the following type
TYPE tab_tests is table of NUMBER(15);
In test.pkb, I have the following procedure
PROCEDURE report (
i_cid IN NUMBER
)
IS
test1 tab_tests := tab_tests();
test2 tab_tests;
BEGIN
-- I populate test1 with the data and it works fine. But when I tried to make a sorted nested table with the following command.
I got this error 'ORA-00902: invalid datatype',
a nested table than the following, like a built in Oracle collection method?
execute immediate 'select cast( multiset (select * from table(test1) order by 1) as tab_tests) INTO test2 FROM dual';
END;
View 16 Replies
View Related
Sep 10, 2012
I have report where there are multiple columns and requirement is user may choose his own sorting order from form, any sample .rdf.
CREATE TABLE EMP (EMP_CODE VARCHAR2(12),EMP_NAME VARCHAR2(20),SAL NUMBER);
INSERT INTO EMP VALUES ('1','A',10);
INSERT INTO EMP VALUES ('2','C',3);
INSERT INTO EMP VALUES ('3','B',20);
[Code]..
--note order by is changing, how its doable in report 6i.
View 2 Replies
View Related
May 18, 2011
1) eno list values ASC , DESC
priority Column : 2
2) DNO List Values ASC , DESC
priority column : 1
3) DTNO List Values ASC , DESC
priority column : 3
So i need the sorting order output like this
LIST VALUES ASC (OR) DESC USER SELECT AT RUN TIME ANY VALUE.
ORDER BY DNO DESC , ENO ASC , DTNO ASC
* The Priority is user will enter at run time based on the number the column should be sorting.
View 6 Replies
View Related
Jun 8, 2012
I have three SQLS which I am running using "Union"
e.g
select col1,count(*) from table where type ='parts'
group by col1
union
select col1,count(*) from table where type ='consumables'
group by col1
union
select 'Total',count(*) from table
group by 'Total'
I want to force the total column to be the last row of the select and the parts column to be the first row always. I did try something like prefixing the col1 with an alphabet. But that shows up in the output also. Was looking for a better way!
View 5 Replies
View Related
Dec 15, 2010
I have two list items and from left list item values are populated to right list item through Add and Remove buttons and vice versa.My requirement is
1.) I need to sort the values of list item whenever a new element is added to the list item.
View 1 Replies
View Related
Dec 11, 2010
I have a Group report based on one group.For eg..there is machine (Group) and it has detail records .The problem is there are certain specific machine on which i want sorting to be done the rest will be not sorted.
machine WX
Details not be sorted
machine sh4
Details to be sorted
machine sh5
Details to be sorted
machine AN1
Details not to be sorted
View 12 Replies
View Related
Dec 15, 2011
Jow can i sort field data getting from formula column. The filed that i want to sort have source of that formula column. When i use order by clause with :abc ---(formula column) then it doesn't not work.
View 3 Replies
View Related
Apr 25, 2013
I have a table in which I extract the year and the month and both in combination (from a date type). This is needed to summarize for example the year in a chart.
I need the combination of month and year because people could do a query which switches through years. For expample: From 02.2012 to 03.2013.My problem is I dont know how to tell anychart to sort the dates. I have already tried:
to_number(to_char(testdate,'YYYY')) as Year,
to_number(to_char(testdate,'YYYY'))||to_number(to_char(testdate,'MM')) as MonthyearApex now sorts:
20121,201212,20122
I would like that apex realizes to order:
1.2012,2.2012,3.2012 .........01.2013,02.2013.03.2013
The report itself has now four date relating collums:
1) Date (Type Date)
2) Year (Type Number)
3) Month (Type Number)
4) Monthyear (Type varchar)
View 3 Replies
View Related
Nov 30, 2010
Is there a way to short a Matrix report? The query shorts correctly in PLSQL but not in the generated report file.
There are columns like Date,Device,Operator Id etc and the report should be able to short depending on the requirement. For example,
it should be able to short by device, or by Date or both. I tried sorting in the 'Break order' but doesn't come out as required.
View 6 Replies
View Related