GROUP BY grouping sets
Hello everybody,
I have this query
SELECT ALL
M_PAGAMENTO||' '||D_TIPO MPAGA,
grouping(F.KIND_F),
DECODE (grouping(F.KIND_F), 0 , 'Totali IVA',F.KIND_F) a1,
case
when grouping(F.KIND_F) = 1 then F.KIND_F
when grouping(F.KIND_F) = 0 then 'Totali IVA'
end TIPOF,
F.KIND_F TIPOF,
COUNT(*) NFATTURE,
sum(F.TOT_FT) TFATTURA, sum(F.BOLLO) TBOLLO,
K_IVA, SUM(FA.IPBFA) TIMP, SUM(FA.IPSFA) TIPS
FROM A_FATTURE F,A_PAZIENTI A,TIPOLOGIA_PAGAMENTI p ,A_FATTURE_ALIQUOTE FA
where (F.TIPORD = A.TIPORD AND F.K_CODE = A.K_CODE AND F.ANNO = A.ANNO)
AND (FA.TIPORD = F.TIPORD AND FA.K_CODE = F.K_CODE AND FA.ANNO = F.ANNO AND FA.N_FATT_D = F.N_FATT_D)
and p.ID_TIPO = f.M_PAGAMENTO
&MYWHERE
GROUP BY grouping sets (M_PAGAMENTO||' '||D_TIPO,F.KIND_F),K_IVA
ORDER by 1
Why I get this result(A1, tipof) = NULL but they would be = 'D' (F.KIND_F ='D'
MPAGA GROUPING(F.KIND_F) A1 TIPOF TIPOF NFATTURE TFATTURA TBOLL K_IVA TIMP TIPS
01 Contante 1 5 3183,24 7,24 20 250 50
01 Contante 1 3 2342,43 5,43 FC 5,43 0
01 Contante 1 50 7024,61 9,91 ES 24458,91 0
02 Assegno 1 1 780,81 1,81 FC 1,81 0
02 Assegno 1 2 816,96 1,81 ES 755,15 0
02 Assegno 1 1 780,81 1,81 20 50 10
04 Carta di credito 1 1 780,81 1,81 FC 1,81 0
04 Carta di credito 1 1 780,81 1,81 20 50 10
04 Carta di credito 1 1 780,81 1,81 ES 719 0
0 Totali IVA Totali IVA D 53 8622,37 23,53 ES 25933,06 0
0 Totali IVA Totali IVA D 5 3904,05 9,05 FC 9,05 0
0 Totali IVA Totali IVA D 7 4744,86 10,86 20 350 70where I am wrong?
thanks for any help
Rosario,
Those rows where grouping(f.kind_f) = 1 are superaggregate rows where you are grouping by M_PAGAMENTO||' '||D_TIPO,K_IVA. So f.kind_f doesn't come into play for these rows, and it shows a null value.
You can of course hard code a 'D' value in there, but values of the f.kind_f column are always null at this grouping level.
See this example:
SQL> select deptno
2 , job
3 , extract(year from hiredate)
4 , sum(sal)
5 , grouping(job)
6 from emp
7 group by deptno
8 , grouping sets (job,extract(year from hiredate))
9 /
DEPTNO JOB EXTRACT(YEARFROMHIREDATE) SUM(SAL) GROUPING(JOB)
10 CLERK 1300 0
10 MANAGER 2450 0
10 PRESIDENT 5000 0
20 CLERK 1900 0
20 ANALYST 6000 0
20 MANAGER 2975 0
30 CLERK 950 0
30 MANAGER 2850 0
30 SALESMAN 5600 0
10 1981 7450 1
10 1982 1300 1
20 1980 800 1
20 1981 5975 1
20 1982 3000 1
20 1983 1100 1
30 1981 9400 1
16 rijen zijn geselecteerd.
SQL> select deptno
2 , job
3 , extract(year from hiredate)
4 , sum(sal)
5 , grouping(job)
6 , decode(grouping(job),1,job)
7 from emp
8 group by deptno
9 , grouping sets (job,extract(year from hiredate))
10 /
DEPTNO JOB EXTRACT(YEARFROMHIREDATE) SUM(SAL) GROUPING(JOB) DECODE(GR
10 CLERK 1300 0
10 MANAGER 2450 0
10 PRESIDENT 5000 0
20 CLERK 1900 0
20 ANALYST 6000 0
20 MANAGER 2975 0
30 CLERK 950 0
30 MANAGER 2850 0
30 SALESMAN 5600 0
10 1981 7450 1
10 1982 1300 1
20 1980 800 1
20 1981 5975 1
20 1982 3000 1
20 1983 1100 1
30 1981 9400 1
16 rijen zijn geselecteerd.Regards,
Rob.
Similar Messages
-
Hi,
Is there a way to read group members of site owner group via SharePoint hosted app . The "Who can view the membership of the group? " is set to Group members only. As per my research SCA can only view the group members of site owner group
if this settings is applied.
Thanks,
Sudhir
Sudhir rawatSee this.
Avoid changing the MaxPageSize LDAP query policy
http://jeftek.com/219/avoid-changing-the-maxpagesize-ldap-query-policy/
Regards~Biswajit
Disclaimer: This posting is provided & with no warranties or guarantees and confers no rights.
MCP 2003,MCSA 2003, MCSA:M 2003, CCNA, MCTS, Enterprise Admin
MY BLOG
Domain Controllers inventory-Quest Powershell
Generate Report for Bulk Servers-LastBootUpTime,SerialNumber,InstallDate
Generate a Report for installed Hotfix for Bulk Servers -
Group by Grouping sets in obiee11g query
Hi Experts
I have few unbalanced heirarchies in the rpd. I have created level beased heirarchy for those ragged and skipped hierarchy but while generating the report using those hierarchy generates a huge SQL involving 20-30 UNION ALLs . Instead it should have generated comparatively smaller query using Group by Grouping Sets but it is not.
I have also tried enabling this parameter in DB properties in OBIEE11g ( changed the default DB from 9i to 11g in obiapps 7.9.6.3 rpd) but still no use .
As a result of huge query geenration the performance is badly impacted.
Any thought on this pls.I have run into the same problem. Any hints about what might be the reason or, even better, how to address it, will be more than welcome.
thanks in advance -
GROUP BY GROUPING SETS Clarification of Format
Hello.
I am trying to validate the answers to 2 questions I have listed below.
Would it be possible for someone to assist me with clarifying these 2 questions and answer statements? Please clarify the portion of the answer that is in
Bold Text and Italicized. Why is one answer enclosed in brackets and the other not?
Basically I need to figure out how to determine the syntax of these parenthesis and why they differ from each question. Is it a format issue or is it based on how the question is asked.
Question #1-
You are a developer for a Microsoft SQL Server 2008 R2 database instance used to support a customer service application.
You create tables named complaint, customer, and product as follows:
CREATE TABLE [dbo].[complaint] ([ComplaintID] [int], [ProductID] [int], [CustomerID] [int], [ComplaintDate] [datetime]);
CREATE TABLE [dbo].[customer] ([CustomerID] [int], [CustomerName] [varchar](100), [Address] [varchar](200), [City] [varchar](100), [State] [varchar](50), [ZipCode] [varchar](5));
CREATE TABLE [dbo].[product] ([ProductID] [int], [ProductName] [varchar](100), [SalePrice] [money], [ManufacturerName] [varchar](100));
You need to write a query to sum the sales made to each customer who has made a complaint by the following entries:
·Each customer name
·Each product name
·The grand total of all sales
Which SQL query should you use?
SELECT c.CustomerName, p.ProductName, SUM(p.SalePrice) AS Sales
FROM product p
INNER JOIN complaint com ON p.ProductID = com.ProductID
INNER JOIN customer c ON com.CustomerID = c.CustomerID
GROUP BY GROUPING SETS ((c.CustomerName), (p.ProductName), ());
Question #2 -
You are a developer for a Microsoft SQL Server 2008 R2 database instance.
You create tables named order, customer, and product as follows:
CREATE TABLE [dbo].[order] ([OrderID] [int], [ProductID] [int], [CustomerID] [int],[OrderDate] [datetime]);
CREATE TABLE [dbo].[customer] ([CustomerID] [int], [CustomerName] [varchar](100),[Address] [varchar](200), [City] [varchar](100), [State] [varchar](50),
[ZipCode] [varchar](5));
CREATE TABLE [dbo].[product] ([ProductID] [int], [ProductName] [varchar](100), [SalePrice] [money], [ManufacturerName] [varchar](100));
You need to write a query to sum the sales made to each customer by the following entries:
·The Customer name and product name
·The grand total of all sales
Which SQL query should you use?
SELECT c.CustomerName,p.ProductName,SUM(p.SalePrice) AS Sales
FROM product p
INNER JOIN [order] o ON p.ProductID = o.ProductID
INNER JOIN customer c ON o.CustomerID = CustomerID
GROUP BY GROUPING SETS ((c.CustomerName, p.ProductName), ());
Your help would be highly appreciated. :)
ThanksIts just to identify the GROUPING SET.When you enclose, the grouping would take for the combination.
Ok, it would be better to see with an example as below:
create table T1 (Col1 Varchar(100),Col2 int,Col3 int)
Insert into T1 Select 'SQL',10,100
Insert into T1 Select 'SQL',11,100
Insert into T1 Select 'Oracle',20,500
SELECT p.col1,p.col2,SUM(p.col3) AS Sales
FROM T1 p
GROUP BY GROUPING SETS ((p.Col1,p.Col2), ());/*Oracle 20 500
SQL 10 100
SQL 11 100
NULL NULL 700*/
SELECT p.col1,p.col2,SUM(p.col3) AS Sales
FROM T1 p
GROUP BY GROUPING SETS ((p.Col1),(p.Col2), ());
/*NULL 10 100
NULL 11 100
NULL 20 500
NULL NULL 700
Oracle NULL 500
SQL NULL 200*/
Drop table T1 -
GROUP BY GROUPING SETS for a selected month and for year to date
Below is a code example to demonstrate this question:
declare @test table (ID int, Quantity int, Day date);
insert into @test values
(4, 500, '1/18/2014'),
(4, 550, '1/28/2014'),
(7, 600, '1/10/2014'),
(7, 750, '1/11/2014'),
(7, 800, '1/20/2014'),
(1, 100, '1/2/2014'),
(1, 125, '1/10/2014'),
(8, 300, '1/7/2014'),
(9, 200, '1/17/2014'),
(9, 100, '1/22/2014'),
(4, 900, '2/18/2014'),
(4, 550, '2/28/2014'),
(7, 600, '2/10/2014'),
(7, 700, '2/11/2014'),
(7, 800, '2/20/2014'),
(1, 100, '2/2/2014'),
(1, 150, '2/10/2014'),
(8, 300, '2/7/2014'),
(9, 200, '2/17/2014'),
(9, 100, '2/22/2014'),
(4, 500, '3/18/2014'),
(4, 550, '3/28/2014'),
(7, 600, '3/10/2014'),
(7, 750, '3/11/2014'),
(7, 800, '3/20/2014'),
(1, 100, '3/2/2014'),
(1, 325, '3/10/2014'),
(8, 300, '3/7/2014'),
(9, 200, '3/17/2014'),
(9, 100, '3/22/2014'),
(4, 500, '4/18/2014'),
(4, 550, '4/28/2014'),
(7, 100, '4/10/2014'),
(7, 750, '4/11/2014'),
(7, 800, '4/20/2014'),
(1, 100, '4/2/2014'),
(1, 325, '4/10/2014'),
(8, 300, '4/7/2014'),
(9, 200, '4/17/2014'),
(9, 100, '4/22/2014'),
(4, 500, '5/18/2014'),
(4, 550, '5/28/2014'),
(7, 600, '5/10/2014'),
(7, 750, '5/11/2014'),
(7, 50, '5/20/2014'),
(1, 100, '5/2/2014'),
(1, 325, '5/10/2014'),
(8, 300, '5/7/2014'),
(9, 200, '5/17/2014'),
(9, 100, '5/22/2014');
--detail
select *
from @test;
--aggregation
select
TotalQuantity = sum(Quantity),
[Month] = month(Day)
from @test
group by
grouping sets
(month(Day)),
(year(Day))
go
This is the aggregation query result:
However, the desired result is to return only two rows: one row for month 3 and the other row for year to date (in the picture above YTD is the row that appears with {null} in the Month column). Is there a way to achieve this goal by modifying the
sample code above? The requirement is to only read the data once (do not want a solution that involves a UNION which implies reading the data twice).you can add required filters in having clause. Here is the query -
select
TotalQuantity = sum(Quantity),
[Month] = month(Day)
from @test
group by
grouping sets
(month(Day)),
(year(Day))
having
month(Day) = 3 or month(Day) is null; -
Changing from "Pass Through" as Default in Blend Mode in a Group Folder Layer Set
Hello Forum gurus!
Using a MacBook Pro, 10.5.4. Painting with CS2. My question is two-fold.
When the Group layer folder in a layer set is selected, it is displaying the "Pass Through" blend mode by default. Is there a special convenience to this? (Best use for pass through blend mode)
Also, How may I change the default in this mode to be "Normal" as the setting when creating a Group folder layer set?
Thanks!!
ColeneMatthias, now I understand. We're both right from different perspectives. If you want the adjustment layer (should there be one within the group) to affect all layers below the group (perhaps because that's the way the image looked before you made the group in the first place), then Pass Through is your blend mode. If you want that adjustment layer to affect only those layers within the group (which I often do), then Normal (or some other) is your blend mode.
-
Where Used for Code groups or Selected Sets
Dear all,
can any body plz tell me how can i know which code group or selected set is used in what qualitative MICs.
either any report or transaction...
thanks in advance
zeeshanHi Zeeshan,
According to my information,,,
For Code Group
In QS41/42/43/44, reach up to the second screen "Change View: Codes" Overview. And then click on the "Used in Selected Set" Or short key "CntrlShiftF3"
For Selected Set.
I think no such std sap report is available. But what you can do is use the work bench CWBQM in display mode,,,,,
- CWBQM---> select the "Current Working Area" as "Q_OPR_000000000010".
- Apply the Basic Selection or Additional Selection Criteria" and then press Cntrl+F7.
- the list of the MIC data will be available here.
Or
You have to write done a query SQVI
Or
Develop a customized report.
Regards,
Shyamal -
Code groups, codes & selected sets during UD
Dear Friends,
Can I create my own catalog types.
I have created my own catalog types.
1) For Usage Decision (R)
2) For Defets recording (P)
During defect recording the system is picking the code groups & codes created by me and which are assigned . It is not showing other ones.
But during Usage decision it is picking all the code groups, codes & selected sets attached to standard UD catalog "3".
I am unable to understand how the system is behaving like this.
I have created my own notification type Y1. I have created my Catalog profile (YQM000001).
I have assigned this profile to inspection type.
I have assigned this notification type to inspection type.
In the catalog profile YQM000001, I have assigned two catalogs (R & P).
In catalogs & catalog profile for notification type, problems field assigned the catalog type "P".
One more issue while recording the defects I am getting notification type as Y1 (created by me) but the catalog profile is showing standard one "QM0000001".
I am unable to understand these all. Do anybody has got any solution.Dear Anuradha,
There is no need to create separate catalog type for your problem of displaying specific UD codes while giving user decision. You can assign the specific 'UD selected set' from catalog type 3 ( User decision) in SPRO ' Maintain inspection type' for QM. Following is the path you can assign the desired UD option you need to see while recording UD:
SPRO >> Quality Management >> Quality Inspection >> Inspection lot creation >> Maintain inspection types >>execute >> select the inspection type say '01' and view details >> there will be field UD selected set, assign the specific selected set made for your plant and save.
By doing this when you go for giving any UD, codes defined by you only will be displayed (not all).
Didn't understand your issue related to notification, but in same above screen you can also assign notification type for particular insp. type.
Looking at your requirement there is no need to create separate insp type or notification type just make proper use of existing one and do proper assignment.
Please let me know if you have any problem in resolving this.
Best Regards,
Shekhar -
Average getting calculated incorrectly using group by grouping sets
Hi All
I am using the group by grouping sets to calulate the running totals of aggregate functions like count, sum & avg.
I get the grand totals of count & sum perfectly right but with avg i am getting the averages incorrectly as the number of rows retrieved by the select query increases.
With few rows (3-4) the averages are round about correct but when the number of rows retreived increase say 5 or more than 5 I get absurd average figures
Here is the query I am using
<code>
select AGENT.NAME,
sum(decode(ACTIVITY.status,'New',1)) cnt,
sum(decode(ACTIVITY.status,'Open',1)) sumopen ,
round(avg( decode (ACTIVITY.status,'Open',ACTIVITY.STATUS_DIFF)),0) avgopen,
sum(decode(ACTIVITY.status,'Sent',1)) sumsent,
round(avg( decode (ACTIVITY.status,'Sent',ACTIVITY.STATUS_DIFF)),0) avgsent,
sum(decode(ACTIVITY.status,'Dead',1)) sumdead,
round(avg( decode (ACTIVITY.status,'Dead',ACTIVITY.STATUS_DIFF)),0) avgdead
from ACTIVITY, REQUEST , AGENT
where
REQUEST.DEALER_NUMBER = AGENT.DEALER_ID
and REQUEST.CONFIRMATION='Y'
and REQUEST.REQUEST_ID = ACTIVITY.REQUEST_ID
and REQUEST.REQUEST_TYPE='B'
and ACTIVITY.ACTIVITY_DATE between to_date('2006-01-01 ','YYYY-MM-DD') and to_date('2006-08-31','YYYY-MM-DD')
group by grouping sets((AGENT.DEALER_ID,AGENT.NAME), ())
</code>
Do let me know your suggestions
RegardsNot sure but may be
See below query
SQL> SELECT deptno,ROUND(AVG(sal))
2 FROM emp
3 GROUP BY ROLLUP(deptno,sal+rownum);
DEPTNO ROUND(AVG(SAL))
10 1300
2450
5000
"2917" ---Sub total
20 800
1100
2975
3000
3000
"2175" ---Sub total
30 950
1250
1250
1500
1600
2850
"1567" ---Sub total
"2073" ----Grand total
18 rows selected.
Now you want
SQL> SELECT (2917+2175+1567)/3 FROM dual;
(2917+2175+1567)/3
2219.66667
While it is
SQL> SELECT ROUND(SUM(sal)/COUNT(*)) FROM emp;
ROUND(SUM(SAL)/COUNT(*))
2073Khurram -
Authorisation for MAster Group or Target Group or Profile set
Hi
How can we restrict certain users from accessing certain Master Groups or Target Groups or Profile sets?
For example we may not want employees in Europe to access target grp pr master grp of Customers in US.
How to do that?
Thanks in advance, reward points for any help.
Regards,
MonicaHi Monica,
did u find an answer for this query on Target groups
Please let me know
Thanks
Edmonds -
WHAT IS THE DIFFERENCE BETWEEN PHRASE GROUP AND PHRASE SET?
WHAT IS DIFFERENCE BETWEEN PHRASE GROUP AND PHRASE SET?
Hi Ramya,
Definition of a Phrase group is a number of phrases contained in a phrase library grouped according to logical criteria. A phrase can be assigned to only one phrase group.
Phrase set is grouping of phrases for a purpose which includes allowed phrases for a value assignment type and Default phrases for a value assignment type. A phrase can be assigned to a number of phrase sets.
Hope this helps you
Best Regards
Srinivas -
Transaction code to change group indicator & group number of a routine
Transaction code to change group indicator & group number of a routine
Post Author: paul.carpenter
CA Forum: Formula
Sorry for the ignorance. I did a little more playing, created a group summary count, then checked it against my record count per group.
All set now! -
Group and Group counter in Routing
Hi all,
what is group and group counter in routing , how these are used in routing , please explain.
Regards,
Joseph.Dear Joseph,
1.Each routing is stored against a group and group counter no.
2.When we create routing without respect to any material and only by giving the plant,the set of operations gets saved under one
group counter and group no.
4.Many materials can be assigned to this same group and group counter no,so that the routing is valid for all the materials included.
5.When you create a routing for material specific,the set of operation gets saved in a group no and group counter no as 01,when
you create another routing with another set of operations for the same material,plant and task list combination now the group no
remains same and the group counter gets saved under 02.
6.This data can be further helpful in assigning the routing data in the production version,.
Check and revert
Regards
S Mangalraj -
I have a bunch of data I need to transform and "group by groups." Let me explain by an example:
SQL> create table orig_data as
2 select distinct job, deptno
3 from scott.emp e
4 /
Table created.
SQL> select job
2 , deptno
3 from orig_data
4 order by
5 job
6 , deptno
7 /
JOB DEPTNO
ANALYST 20
CLERK 10
CLERK 20
CLERK 30
MANAGER 10
MANAGER 20
MANAGER 30
PRESIDENT 10
SALESMAN 30
9 rows selected.The real-world data is about 5 million rows.
First I group by job (I use xmlagg here because I am on version 11.1 and therefore no listagg ;-) ):
SQL> select od.job
2 , rtrim(xmlagg(xmlelement(d,od.deptno,',').extract('//text()') order by od.deptno),',') deptnos
3 from orig_data od
4 group by od.job
5 /
JOB DEPTNOS
ANALYST 20
CLERK 10,20,30
MANAGER 10,20,30
PRESIDENT 10
SALESMAN 30I notice here that both job CLERK and MANAGER has the same set of deptnos.
So if I group by deptnos I can get this result:
SQL> select s2.deptnos
2 , rtrim(xmlagg(xmlelement(j,s2.job,',').extract('//text()') order by s2.job),',') jobs
3 from (
4 select od.job
5 , rtrim(xmlagg(xmlelement(d,od.deptno,',').extract('//text()') order by od.deptno),',') deptnos
6 from orig_data od
7 group by od.job
8 ) s2
9 group by s2.deptnos
10 /
DEPTNOS JOBS
10 PRESIDENT
10,20,30 CLERK,MANAGER
20 ANALYST
30 SALESMANMy requirement is to identify all such unique groups of deptnos in my orig_data table, give each such group a surrogate key in a parent table, and then populate two child tables with the deptnos of each group and the jobs that have that group of deptnos:
SQL> create table groups (
2 groupkey number primary key
3 )
4 /
Table created.
SQL> create table groups_depts (
2 groupkey number references groups (groupkey)
3 , deptno number(2)
4 )
5 /
Table created.
SQL> create table groups_jobs (
2 groupkey number references groups (groupkey)
3 , job varchar2(9)
4 )
5 /
Table created.For the surrogate groupkey I can just use a rownumber on my group by deptnos query:
SQL> select row_number() over (order by s2.deptnos) groupkey
2 , s2.deptnos
3 , rtrim(xmlagg(xmlelement(j,s2.job,',').extract('//text()') order by s2.job),',') jobs
4 from (
5 select od.job
6 , rtrim(xmlagg(xmlelement(d,od.deptno,',').extract('//text()') order by od.deptno),',') deptnos
7 from orig_data od
8 group by od.job
9 ) s2
10 group by s2.deptnos
11 /
GROUPKEY DEPTNOS JOBS
1 10 PRESIDENT
2 10,20,30 CLERK,MANAGER
3 20 ANALYST
4 30 SALESMANThat query I can use for a (slow) insert into my three tables in this simple manner:
SQL> begin
2 for g in (
3 select row_number() over (order by s2.deptnos) groupkey
4 , s2.deptnos
5 , rtrim(xmlagg(xmlelement(j,s2.job,',').extract('//text()') order by s2.job),',') jobs
6 from (
7 select od.job
8 , rtrim(xmlagg(xmlelement(d,od.deptno,',').extract('//text()') order by od.deptno),',') deptnos
9 from orig_data od
10 group by od.job
11 ) s2
12 group by s2.deptnos
13 ) loop
14 insert into groups values (g.groupkey);
15
16 insert into groups_depts
17 select g.groupkey
18 , to_number(regexp_substr(str, '[^,]+', 1, level)) deptno
19 from (
20 select rownum id
21 , g.deptnos str
22 from dual
23 )
24 connect by instr(str, ',', 1, level-1) > 0
25 and id = prior id
26 and prior dbms_random.value is not null;
27
28 insert into groups_jobs
29 select g.groupkey
30 , regexp_substr(str, '[^,]+', 1, level) job
31 from (
32 select rownum id
33 , g.jobs str
34 from dual
35 )
36 connect by instr(str, ',', 1, level-1) > 0
37 and id = prior id
38 and prior dbms_random.value is not null;
39
40 end loop;
41 end;
42 /
PL/SQL procedure successfully completed.The tables now contain this data:
SQL> select *
2 from groups
3 order by groupkey
4 /
GROUPKEY
1
2
3
4
SQL> select *
2 from groups_depts
3 order by groupkey, deptno
4 /
GROUPKEY DEPTNO
1 10
2 10
2 20
2 30
3 20
4 30
6 rows selected.
SQL> select *
2 from groups_jobs
3 order by groupkey, job
4 /
GROUPKEY JOB
1 PRESIDENT
2 CLERK
2 MANAGER
3 ANALYST
4 SALESMANI can now from these data get the same result as before (just to test I have created the desired data):
SQL> select g.groupkey
2 , d.deptnos
3 , j.jobs
4 from groups g
5 join (
6 select groupkey
7 , rtrim(xmlagg(xmlelement(d,deptno,',').extract('//text()') order by deptno),',') deptnos
8 from groups_depts
9 group by groupkey
10 ) d
11 on d.groupkey = g.groupkey
12 join (
13 select groupkey
14 , rtrim(xmlagg(xmlelement(j,job,',').extract('//text()') order by job),',') jobs
15 from groups_jobs
16 group by groupkey
17 ) j
18 on j.groupkey = g.groupkey
19 /
GROUPKEY DEPTNOS JOBS
1 10 PRESIDENT
2 10,20,30 CLERK,MANAGER
3 20 ANALYST
4 30 SALESMANSo far so good. This all works pretty much as desired - except for a couple of things:
The very simple loop insert code will be slow. OK, it is a one-time conversion job (in theory, but very few times at least) so that could probably be acceptable (except for my professional pride ;-) .)
But worse is, that I have groups where the string aggregation won't work - the string would have to be about varchar2(10000) which won't work in SQL in the group by :-( .
So I have tried an attempt using collections. First a collection of deptnos:
SQL> create type deptno_tab_type as table of number(2)
2 /
Type created.
SQL> select od.job
2 , cast(collect(od.deptno order by od.deptno) as deptno_tab_type) deptnos
3 from orig_data od
4 group by od.job
5 /
JOB DEPTNOS
ANALYST DEPTNO_TAB_TYPE(20)
CLERK DEPTNO_TAB_TYPE(10, 20, 30)
MANAGER DEPTNO_TAB_TYPE(10, 20, 30)
PRESIDENT DEPTNO_TAB_TYPE(10)
SALESMAN DEPTNO_TAB_TYPE(30)All very good - no problems here. But then a collection of jobs:
SQL> create type job_tab_type as table of varchar2(9)
2 /
Type created.
SQL> select s2.deptnos
2 , cast(collect(s2.job order by s2.job) as job_tab_type) jobs
3 from (
4 select od.job
5 , cast(collect(od.deptno order by od.deptno) as deptno_tab_type) deptnos
6 from orig_data od
7 group by od.job
8 ) s2
9 group by s2.deptnos
10 /
group by s2.deptnos
ERROR at line 9:
ORA-00932: inkonsistente datatyper: forventede -, fik XAL_SUPERVISOR.DEPTNO_TAB_TYPENow it fails - I cannot group by a collection datatype...
I am not asking anyone to write my code, but I know there are sharper brains out there on the forums ;-) .
Would anyone have an idea of something I might try that will allow me to create these "groups of groups" even for larger groups than string aggregation techniques can handle?
Thanks for any help, hints or tips ;-)The "group-by-collection" issue can be solved by creating a container object on which we define an ORDER method :
SQL> create type deptno_container as object (
2 nt deptno_tab_type
3 , order member function match (o deptno_container) return integer
4 );
5 /
Type created
SQL> create or replace type body deptno_container as
2 order member function match (o deptno_container) return integer is
3 begin
4 return case when nt = o.nt then 0 else 1 end;
5 end;
6 end;
7 /
Type body created
Then a multitable INSERT can do the job, after unnesting the collections :
SQL> insert all
2 when rn0 = 1 then into groups (groupkey) values (gid)
3 when rn1 = 1 then into groups_jobs (groupkey, job) values(gid, job)
4 when rn2 = 1 then into groups_depts (groupkey, deptno) values(gid, deptno)
5 with all_groups as (
6 select s2.deptnos
7 , cast(collect(s2.job order by s2.job) as job_tab_type) jobs
8 , row_number() over(order by null) gid
9 from (
10 select od.job
11 , deptno_container(
12 cast(collect(od.deptno order by od.deptno) as deptno_tab_type)
13 ) deptnos
14 from orig_data od
15 group by od.job
16 ) s2
17 group by s2.deptnos
18 )
19 select gid
20 , value(j) job
21 , value(d) deptno
22 , row_number() over(partition by gid order by null) rn0
23 , row_number() over(partition by gid, value(j) order by null) rn1
24 , row_number() over(partition by gid, value(d) order by null) rn2
25 from all_groups t
26 , table(t.jobs) j
27 , table(t.deptnos.nt) d
28 ;
15 rows inserted
SQL> select * from groups;
GROUPKEY
1
2
3
4
SQL> select * from groups_jobs;
GROUPKEY JOB
1 SALESMAN
2 PRESIDENT
3 CLERK
3 MANAGER
4 ANALYST
SQL> select * from groups_depts;
GROUPKEY DEPTNO
1 30
2 10
3 10
3 30
3 20
4 20
6 rows selected
Works great on the sample data but how this approach scales on a much (much) larger dataset is another story :) -
Anyconnect tunnel-group and group-policy from LDAP
Recently we've changed from LOCAL to LDAP authentication and added additional group-policies for different users to increase security.
To prevent users from selecting an incorrect group-policy, the LDAP server provides a IETF-Radius-Class value which matches the different group-policy names.
It is my understanding that the authentication method is provided by the tunnel-group.
tunnel-group DefaultWEBVPNGroup general-attributes
authentication-server-group LDAP_AD
This all works, but for _one_ of the group policies i'd like to enable (external) two factor authentication. Two enable two factor auth a 'secondary-authentication-server-group' needs to be set in the tunnel-group.
Creating a tunnel-group which maches the name of the group-policy doesn't seem to have any effect. When listing the connected users via "show vpn-sessiondb anyconnect", it always states the correct Group Policy but also always DefaultWEBVPNGroup.
When enabling the listing of tunnel-groups for webvpn, thus allowing users to select their own tunnel-group, the two factor auth does work.
To summarize, is it possible to let LDAP decide which tunnel-group is used or is there another way to have different group policies without users being able to choose ?Fabian,
Your connection lands on a tunnel group and picks a group policy.
A typical way to overcome the problem you're indicating is by using group-url.
a URL is bound to a specific tunnel-group and allows you to land directly on the one you desire.
vide:
http://www.cisco.com/c/en/us/support/docs/security/asa-5500-x-series-next-generation-firewalls/98580-enable-group-dropdown.html
M.
Maybe you are looking for
-
EPUB exported from InDesign works on iPad and not on Android tablets
I've edxported several similar books to EPUB from InDesign CS5, using the same technique each. After exporting from InDesign, there's a lot of tweaking of the HTML code and some changes to the content.opf and toc.ncx, but the finished product for all
-
Hey, I have just purchased a 4th gen nano for a mate, and we were trying to get an older game from an older gen nano (not sure which one) which came with the older iPod. The game is basically music trivia, where the iPod plays the song and you have s
-
How to set "All day event " as default in Calendar in 9630
In BB 9630 how do I set "All day event " as the default in Calendar?
-
Improving Acrobat Security ?
Acrobat provides an easy means for the password protection of PDF documents. The approach is advantageous in that the documents can be read with the freely available Adobe Reader with usage of the appropriate passwords. Unfortunately, as is well know
-
TabIndex in many Components?
I have a JFrame with many components (TextFields, JCheckBox, radioButtons, etc), and its are in many Panels with diferents Layouts. How can I change the tabindex (the orden in wich the components are getting the focus when I Press de key Tab)?. Thank