Need a group of clause for two variables in a table
I can't find any way to merge the two variables in a group statement with vertical output and horizobtable.The statement that I had for a vertical output is (10 gr 2):
Select to_char (d.begin_interval_time, 'YYYY-MM-DD') as Datenumber,
w.wait_class as Type,
round (sum (w.total_waits) / 1024/1024, 0) while "Tot-wait."
dba_hist_snapshot d, dba_hist_bg_event_summary w
where d.snap_id = w.snap_id
To_char (d.begin_interval_time, 'YYYY-MM-DD') group, w.wait_class
order by to_char (d.begin_interval_time, 'YYYY-MM-DD');
2010-02-28 system IO 234567
2010-02-28 user IO 34444
.
.
2010-03-01 system I / 0 773777
.
But I wanted to have the following summary output in a SQL:
User IO system IO Idle commit... and so on
2010-02-26 3442322 344555 335455 5
2010-02-27 533222 2233 445455 2334
2010-02-28 3434444 244444 345555 39
2010-03-01 34444 55445 3444 534
Someone has an idea?
Do you mean that?
SQL> select to_char(d.begin_interval_time, 'YYYY-MM-DD') as Datenumber,
2 round(sum(decode(w.wait_class,'Concurrency', w.total_waits/1024/1024, 0)),0) as "Concurrency",
3 round(sum(decode(w.wait_class,'System I/O', w.total_waits/1024/1024, 0)),0) as "System I/O",
4 round(sum(decode(w.wait_class,'User I/O', w.total_waits/1024/1024, 0)),0) as "User I/O",
5 round(sum(decode(w.wait_class,'Configuration', w.total_waits/1024/1024, 0)),0) as "Configuration",
6 round(sum(decode(w.wait_class,'Other', w.total_waits/1024/1024, 0)),0) as "Other",
7 round(sum(decode(w.wait_class,'Commit', w.total_waits/1024/1024, 0)),0) as "Commit",
8 round(sum(decode(w.wait_class,'Idle', w.total_waits/1024/1024, 0)),0) as "Idle"
9 from dba_hist_snapshot d, dba_hist_bg_event_summary w
10 where d.snap_id = w.snap_id
11 group by to_char(d.begin_interval_time, 'YYYY-MM-DD')
12 order by to_char(d.begin_interval_time, 'YYYY-MM-DD');
DATENUMBER Concurrency System I/O User I/O Configuration Other Commit Idle
---------- ----------- ---------- ---------- ------------- ---------- ---------- ----------
2010-02-22 1 298 0 0 2 0 2107
2010-02-23 1 299 0 0 2 0 2114
2010-02-24 1 300 0 0 2 0 2121
2010-02-25 1 301 0 0 2 0 2129
2010-02-26 1 303 0 0 2 0 2136
2010-02-27 1 304 0 0 2 0 2143
2010-02-28 1 305 0 0 2 0 2150
2010-03-01 0 140 0 0 1 0 988
Max
http://oracleitalia.WordPress.com
Tags: Database
Similar Questions
-
How to create the Group of cache for many to many relationship tables?
Hi, Chris,.
Page 4-4 < < the user manual of the Oracle Database Cache in memory > > there is a saying,
A child table cannot reference multiple parent tables.
If there is a many-to-many relationship table in Oracle and I want to cache in TT, there is not a la carte approach that?
Or I have to logically break his references to the two tables in one of them?
I forgot to mention that I have a root table and one of its child tables is a many-to-many relationship table.Yes, that's correct. You can not exactly this model in TimesTen. You to omit some of the relationships so that things are defined in TimesTen as a pure parent/child relationship. You can also consider putting the tables into groups separate cache. Of course, there are consequences to this:
1. the 'missing' relationship cannot be run by TimesTen. The application must respect/run it. If this is not some updates may not to be propagated to Oracle if they violate the relationship in Oracle.
2 If the parallel AWT is configured (to improve the performance of spread) it will not be used for all tables where they lack of relationships. All updates to the tables in the order will apply.
Chris
-
How to have a prompt for all variables in the startup script?
I was given a script to run that repeated a couple of specific column values many times in queries in the script. I noticed the ability to set variables in scripts, then in the copy of my script, I changed the value repeated a reference variable (starting with '&') and then I executed the script. What I discovered is that the execution of the script appears to present the prompt for the value of the variable EVERY TIME the done variable references, instead of only once at the beginning of the script. What can be possibly right? Is it possible to have this script the only guest (or two, perhaps, for two variables) at the beginning of the script and just have it use this value in the many places in the script need?Yeeees well. In the above example would be: Cancel the definition of entry
BUT, assuming you're sqldev (not), and that you run as a script (F5), you don't need to the above calls, and you will be prompted for the value of each race.
If you run instructions in sqldev (F9), usually, it makes more sense to use bind variables (*: * instead of * & *).Have fun
K. -
Reg - search form for a VO in group by clause
Hello
I have a bar chart that displays data based on the query below.
SELECT THE STATE. BATCH AS STATUSID, STATUS. STATUS, COUNTY (SR. SERVICEREQUEST_ID) AS SRCOUNT
OF SR, SERVICEREQUESTSTATUS STATE SERVICE_REQUEST
WHERE SR. BATCH = STATUS. BATCH
GROUP STATUS. BATCH, STATUS. STATUS, SR. BATCH
It displays the number of SRs against a particular status.
Now, I need to add a search form to this graph with the customer and the date range.
So you need to add the following line to the place where clause.
SR. "CUSTOMER_ID =: customerId AND SR. "BETWEEN REQUESTED_ON: fromDate and: to this day.
But the SR columns. CUSTOMER_ID, SR. REQUESTED_ON also needs to be added to the select clause to create criteria for the search panel view.
The two columns should also be added to the group by clause if you want to add in the select clause.
This would not produce the expected results.
How to create a search with the criteria only form in the where clause. Help, please.
With respect,
Guna[Url http://docs.oracle.com/cd/E16162_01/apirefs.1112/e17483/oracle/jbo/server/ViewObjectImpl.html] ViewObjectImpl has methods to do this programmatically (setQuery, defineNamedWhereClauseParam, setNamedWhereClauseParam) that you can use to manipulate the query variables bind expected and the values of the lie.
John
-
Group By clause in oracle 10g need help
Hello
We have a requirement that get the AR details of aging at the customer level. I wrote the following query to retrieve the correct rows at the invoice level. But now I need calculate the sum of the amounts and I show you the invoice and customer level. Could you please help me how can I group by the client.
Here's the query I used
Select ps.org_id
sobbed. SET_OF_BOOKS_ID
sobbed. CHART_OF_ACCOUNTS_ID
gcc. Company of SEGMENT1
gcc. SEGMENT2 location
gcc. Department of SEGMENT3
gcc. SEGMENT4 account
gcc. Future_1 SEGMENT5
gcc. SEGMENT6 Future_2
gcc. SEGMENT7 Future_3
gcc. CONCATENATED_SEGMENTS gl_cc_concat_kff
ps.trx_number
ps.trx_date
ps.due_date
ps.invoice_currency_code
sob.currency_code SOB_Currency_Code
ps.class
ps.amount_due_original
, ps.amount_due_original * nvl (ps.exchange_rate, 1) acctd_amount_due_original
ps.amount_due_remaining
ps.acctd_amount_due_remaining
ps.status
ps.cust_trx_type_id
ps.customer_site_use_id
ps.customer_trx_id
ps.cash_receipt_id
ps.gl_date
rctlda. CODE_COMBINATION_ID
ps.customer_id
nvl (ATCM. ATTRIBUTE5, ps. CUSTOMER_ID) End_Customer_Id
rc.customer_number
rc2. CUSTOMER_NUMBER Brand_Cust_no
, round ((sysdate-ps.due_date))
of gl_sets_of_books ob
, hr_operating_units or
ar_payment_schedules_all ps
ra_customers rc
ra_cust_trx_line_gl_dist_all rctlda
gl_code_combinations_kfv gcc
ra_customer_trx_all ATCM
ra_customers rc2
where sob.set_of_books_id = ou.set_of_books_id
and ou.organization_id = ps.org_id
and ps.status = 'OP '.
and ps.org_id is not null
and ps. CUSTOMER_ID = rc. CUSTOMER_ID
and ps. CUSTOMER_TRX_ID = rctlda. CUSTOMER_TRX_ID
and rctlda. ACCOUNT_CLASS = "REC".
and rctlda.latest_rec_flag = 'Y '.
and rctlda. CODE_COMBINATION_ID = gcc. CODE_COMBINATION_ID
and ps. CUSTOMER_TRX_ID = ATCM. CUSTOMER_TRX_ID
and gcc. CODE_COMBINATION_ID = 39446
- and ps.trx_number = 1-15O0A8O'
- and rc. CUSTOMER_NUMBER = 1-10PA5KX'
and nvl (ATCM. ATTRIBUTE5, ps. CUSTOMER_ID) = rc2. CUSTOMER_ID
Could someone help me how to recover the same columns with sum (ps.amount_due_original) for each client. I tried to use the group by clause, but it gives to new level of the invoice.
But my req's for each customer the amount of the invoice must be added and it should give the total
Thank you
THEREIf you need to have the amount of the invoice for each customer may also need to check the
CUBE
http://download.Oracle.com/docs/CD/B28359_01/server.111/b28286/statements_10002.htm#sthref9448
and example here
http://download.Oracle.com/docs/CD/B28359_01/server.111/b28286/statements_10002.htm#i2066443and ROLLUP
http://download.Oracle.com/docs/CD/B28359_01/server.111/b28286/statements_10002.htm#sthref9445I couldn't keep up with all your SQL statement, or I could rewrite for you once again
Thank youPublished by: user9532576 on July 21, 2009 09:24
-
I have 1 computer and need to install copies separated by a game for two different users
I need to be able to install two copies separate from Dragon Age: Origins, one for me and one for my girlfriend under our separate user accounts on my computer, how can I do this?
--------------
-
I have CS2, CS 4 on two PCs. I need to buy a laptop for work and I want to put my copy on it. Can I uninstall of either. I'll be able to install on the new lap top?
Maybe, maybe not... According to the new operating system
CS2, Acrobat 7 + Audition 3 (AND PREVIOUS) activation server has disappeared, then read below
l http://helpx.adobe.com/x-productkb/Policy-Pricing/Creative-Suite-2-activation-end-Life.htm
.
You MUST use the special version and the serial number on the page, not your original drive or serial number
.
When you install the special version of CS2 on a Win7 or Win8 or Win10 computer, you may need to right click on the program icon and select compatibility Windows XP in the popup of option
-
I need three PC to use acrobat DC, what I have to do? I'm subscribed to a year, but it is designed for two PC.
You can install the software on as many PCs as you like, but you can activate only two for use at the time and only use one at a time.
Then you can alternate the activations between PC that you use at a given time.
-
Two variables in the name of a table in the FROM clause.
Hello
I have a problem to make this work:
SELECT *.
OF tablename_YY_MM
(This is part of the script I use YY and MM in different tables)
I need to find a way for the script asks me every time on AA and the MM
For example, the current name of the table "tablename_09_08" next month, it will be 'tablename_09_09 '.
It seems simple, but I can't get it to work. There seems to be a problem with concatenate | and the underscore _
Looks like this should be done with PL/SQL?
If anyone can help it will be much appreciated.
Thank you.
Published by: user1067236 on August 11, 2009 02:21
Published by: user1067236 on August 11, 2009 02:23SQL>SELECT * FROM tablename_&YY._&MM; Enter value for yy: 09 Enter value for mm: 08 old 1: SELECT * FROM tablename_&YY._&MM new 1: SELECT * FROM tablename_09_08 SELECT * FROM tablename_09_08
HTH, Urs
-
By the way where and group by clause Cursor
I'm working on a procedure that generates a where clause clause and needs of a group by clause to return the correct results. I'm moving the two where and group variables in the cursor.
The variables are is filled correctly, but when the cursor is created, variables are not in the cursor.
Here's the code I'm working with. It is part of a package, but does no appeal to other parts of the package.
PROCEDURE createFollowUpTask_Exposure (psUppgkedjetyp IN tis.tial.uppgkedjetyp%TYPE NULL by default,
psAlarmtyp IN tis.tial.alarmtyp%TYPE by default NULL,
psSubtyp IN tis.tial.subtyp%TYPE by default NULL,
pnDays in NUMBER NULL by default,
psKampkod IN tis.tiin.kampkod%TYPE by default NULL,
psKatnr IN tis.tiin.katnr%TYPE by default NULL,
psUtgava IN tis.tiin.utgava%TYPE by default NULL,
psKatslag IN tis.tikg.katslag%TYPE by default NULL,
psProdsyst IN tis.tikg.prodsyst%TYPE by default NULL,
psUppgtyp IN tis.tiin.uppgtyp%TYPE by default NULL,
psProdkod IN tis.tiin.prodkod%TYPE by default NULL,
psStatus IN tis.tiin.status%TYPE by default NULL
) AS
--
cTIAL tis.tial%ROWTYPE;
vLopnr tis.tial.lopnr%TYPE;
vSqlWhere VARCHAR2 (4000);
vGroupBy VARCHAR2 (1000): = "tiin.kampkod, tiin.abnr, tiko.fordsalj;
cSelectCursor SYS_REFCURSOR;
vSqlSelect VARCHAR2 (4000);
psDays VARCHAR2 (50);
cRec T_TIAL_REC;
nCount number: = 0;
--
CURSOR cSqlSelect (SqlWhere IN VARCHAR2, GroupBy IN VARCHAR2) IS
SELECT tiin.kampkod, tiin.abnr, tiko.fordsalj, MAX (tici.regdat) ALARMDATE
OF tis.tiin
JOIN tis.tiko ON tiin.kampkod = tiko.kampkod AND tiin.abnr = tiko.abnr
JOIN core.tici ON tiin.kampkod = tici.kampkod AND tiin.abnr = tici.abnr AND tici.inplnr = tiin.inplnr
WHERE 1 = 1 | SqlWhere
GroupBy GROUP;
--
BEGIN
-If these parameters are null, trigger the error
IF psUppgkedjetyp IS NULL and psSubtyp IS NULL THEN
raise_application_error (-20001,
"String from the event or events must be assigned");
END IF;
-Fill the TIAL values
IF psUppgkedjetyp IS NOT NULL THEN
cTIAL.Uppgkedjetyp: = psUppgkedjetyp;
END IF;
--
IF psAlarmtyp IS NOT NULL THEN
cTIAL.Alarmtyp: = psAlarmtyp;
END IF;
--
cTIAL.Handklass: = 't';
cTIAL.Blobid: = 0;
--
IF pnDays IS NOT NULL THEN
psDays: = '+' | pnDays;
END IF;
IF psSubtyp IS NOT NULL THEN
cTIAL.Subtyp: = psSubtyp;
END IF;
-Create Where clause for cursor
vSqlWhere: = ";
IF psKampkod IS NOT NULL THEN
vSqlWhere: = vSqlWhere | "AND tiin.kampkod ="' | psKampkod | " ' ;
END IF;
--
IF psKatnr IS NOT NULL THEN
vSqlWhere: = vSqlWhere | "AND tiin.katnr ="' | psKatnr | " ' ;
END IF;
--
IF psUtgava IS NOT NULL THEN
vSqlWhere: = vSqlWhere | "AND tiin.utgava ="' | psUtgava | " ' ;
END IF;
--
IF psKatslag IS NOT NULL THEN
vSqlWhere: = vSqlWhere | "AND tikg.katslag ="' | psKatslag | " ' ;
END IF;
--
IF psProdsyst IS NOT NULL THEN
vSqlWhere: = vSqlWhere | "AND tikg.prodsyst ="' | psProdsyst | " ' ;
END IF;
--
IF psUppgtyp IS NOT NULL THEN
vSqlWhere: = vSqlWhere | "AND tiin.uppgtyp ="' | psUppgtyp | " ' ;
END IF;
--
IF psProdkod IS NOT NULL THEN
vSqlWhere: = vSqlWhere | "AND tiin.prodkod ="' | psProdkod | " ' ;
END IF;
--
IF psStatus IS NOT NULL THEN
vSqlWhere: = vSqlWhere | "AND tiin.status ="' | psStatus | " ' ;
END IF;
-Browse all records in input parameters of the meeting and set values required TIAL.
I'm IN cSqlSelect (vSqlWhere, vGroupBy)
--
LOOP
-EXTRACT cSelectCursor INTO cRec;
cTIAL.Kampkod: = ";
cTIAL.Abnr: = ";
cTIAL.Sign: = ";
cTIAL.Alarmdate: = ";
cTIAL.Kampkod: = i.Kampkod;
cTIAL.Abnr: = i.Abnr;
cTIAL.Sign: = i.fordsalj;
cTIAL.Alarmdate: = i.alarmdate;
--
nCount: = nCount + 1;
--
IF vLopnr = - 1 THEN
raise_application_error (-20002,
"Error creating task for: ' | '. cTIAL.Kampkod |' '|| cTIAL.Abnr |' Sales representative: ' | cTIAL.Alarmdate);
END IF;
END LOOP;
DBMS_OUTPUT. Put_line (' I created ' | nCount |) "documents.");
END createFollowUpTask_Exposure;
Thanks in advance for any help.Hello
Welcome to the forum!
Try this (untested) example:
PROCEDURE createFollowUpTask_Exposure(psUppgkedjetyp IN tis.tial.uppgkedjetyp%TYPE DEFAULT NULL, psAlarmtyp IN tis.tial.alarmtyp%TYPE DEFAULT NULL, psSubtyp IN tis.tial.subtyp%TYPE DEFAULT NULL, pnDays IN NUMBER DEFAULT NULL, psKampkod IN tis.tiin.kampkod%TYPE DEFAULT NULL, psKatnr IN tis.tiin.katnr%TYPE DEFAULT NULL, psUtgava IN tis.tiin.utgava%TYPE DEFAULT NULL, psKatslag IN tis.tikg.katslag%TYPE DEFAULT NULL, psProdsyst IN tis.tikg.prodsyst%TYPE DEFAULT NULL, psUppgtyp IN tis.tiin.uppgtyp%TYPE DEFAULT NULL, psProdkod IN tis.tiin.prodkod%TYPE DEFAULT NULL, psStatus IN tis.tiin.status%TYPE DEFAULT NULL) AS -- cTIAL tis.tial%ROWTYPE; vLopnr tis.tial.lopnr%TYPE; vSqlWhere VARCHAR2(4000); vGroupBy VARCHAR2(1000) := ' tiin.kampkod, tiin.abnr, tiko.fordsalj'; cSelectCursor SYS_REFCURSOR; vSqlSelect VARCHAR2(4000); psDays VARCHAR2(50); cRec T_TIAL_REC; nCount NUMBER := 0; FUNCTION fnc_cSqlSelect(SqlWhere IN VARCHAR2, GroupBy IN VARCHAR2) RETURN VARCHAR2 IS BEGIN RETURN 'SELECT tiin.kampkod, tiin.abnr, tiko.fordsalj, MAX(tici.regdat) ALARMDATE FROM tis.tiin JOIN tis.tiko ON tiin.kampkod = tiko.kampkod AND tiin.abnr = tiko.abnr JOIN core.tici ON tiin.kampkod = tici.kampkod AND tiin.abnr = tici.abnr AND tici.inplnr = tiin.inplnr WHERE 1 = 1 ' || SqlWhere || ' GROUP BY ' || GroupBy; END fnc_cSqlSelect; BEGIN -- If these parameters are null, raise error IF psUppgkedjetyp IS NULL AND psSubtyp IS NULL THEN raise_application_error(-20001, 'Either Event Chain or Starting Event must be assigned'); END IF; -- Populate TIAL values IF psUppgkedjetyp IS NOT NULL THEN cTIAL.Uppgkedjetyp := psUppgkedjetyp; END IF; -- IF psAlarmtyp IS NOT NULL THEN cTIAL.Alarmtyp := psAlarmtyp; END IF; -- cTIAL.Handklass := 'T'; cTIAL.Blobid := 0; -- IF pnDays IS NOT NULL THEN psDays := '+ ' || pnDays; END IF; IF psSubtyp IS NOT NULL THEN cTIAL.Subtyp := psSubtyp; END IF; -- Create Where clause for cursor vSqlWhere := ''; IF psKampkod IS NOT NULL THEN vSqlWhere := vSqlWhere || ' AND tiin.kampkod = ''' || psKampkod || ''''; END IF; -- IF psKatnr IS NOT NULL THEN vSqlWhere := vSqlWhere || ' AND tiin.katnr = ''' || psKatnr || ''''; END IF; -- IF psUtgava IS NOT NULL THEN vSqlWhere := vSqlWhere || ' AND tiin.utgava = ''' || psUtgava || ''''; END IF; -- IF psKatslag IS NOT NULL THEN vSqlWhere := vSqlWhere || ' AND tikg.katslag = ''' || psKatslag || ''''; END IF; -- IF psProdsyst IS NOT NULL THEN vSqlWhere := vSqlWhere || ' AND tikg.prodsyst = ''' || psProdsyst || ''''; END IF; -- IF psUppgtyp IS NOT NULL THEN vSqlWhere := vSqlWhere || ' AND tiin.uppgtyp = ''' || psUppgtyp || ''''; END IF; -- IF psProdkod IS NOT NULL THEN vSqlWhere := vSqlWhere || ' AND tiin.prodkod = ''' || psProdkod || ''''; END IF; -- IF psStatus IS NOT NULL THEN vSqlWhere := vSqlWhere || ' AND tiin.status = ''' || psStatus || ''''; END IF;ç -- Loop through all records meeting input parameters and set required TIAL values. OPEN cSelectCursor FOR fnc_cSqlSelect(vSqlWhere, vGroupBy); LOOP FETCH cSelectCursor INTO v; -- You must define a variable 'v' to hold the data of cursor EXIT WHEN cSelectCursor%NOTFOUND; --FETCH cSelectCursor INTO cRec; cTIAL.Kampkod := ''; cTIAL.Abnr := ''; cTIAL.Sign := ''; cTIAL.Alarmdate := ''; cTIAL.Kampkod := i.Kampkod; cTIAL.Abnr := i.Abnr; cTIAL.Sign := i.fordsalj; cTIAL.Alarmdate := i.alarmdate; -- nCount := nCount + 1; -- IF vLopnr = -1 THEN raise_application_error(-20002, 'Error Creating task for: ' || cTIAL.Kampkod || ' ' || cTIAL.Abnr || ' Sales Rep: ' || cTIAL.Alarmdate); END IF; END LOOP; CLOSE cSelectCursor; DBMS_OUTPUT.PUT_LINE('I created ' || nCount || ' records.'); END createFollowUpTask_Exposure; /
Kind regards
-
Concatenation of data with the GROUP BY clause
Hi again!
Following my previous thread...
I tried to apply the GROUP BY clause instead of preforming my query with RANK() to manage records NULL... I have a scenario where I also need to concatenate data from several lines.
CREATE TABLE T_EMP (NUMBER OF EMP_NO, NAME VARCHAR2 (20));
INSERT INTO T_EMP VALUES (1001, 'MARK');
INSERT INTO T_EMP VALUES (1002, 'DAVID');
INSERT INTO T_EMP VALUES (1003, "SHAUN");
INSERT INTO T_EMP VALUES (1004, "JILL");
CREATE TABLE T_EMP_DEPT (NUMBER OF EMP_NO, DEPT_NO NUMBER);
INSERT INTO T_EMP_DEPT VALUES (1001, 10);
INSERT INTO T_EMP_DEPT VALUES (1001, 20);
INSERT INTO T_EMP_DEPT VALUES (1002, 10);
INSERT INTO T_EMP_DEPT VALUES (1002, 20);
INSERT INTO T_EMP_DEPT VALUES (1002, 30);
INSERT INTO T_EMP_DEPT VALUES (1003, 20);
INSERT INTO T_EMP_DEPT VALUES (1003, 30);
INSERT INTO T_EMP_DEPT VALUES (1004, 10);
CREATE TABLE T_EMP_VISITS (NUMBER OF EMP_NO, DEPT_NO NUMBER, VISITED DATE);
INSERT INTO T_EMP_VISITS VALUES (1001, 10, 1 JAN 2009');
INSERT INTO T_EMP_VISITS VALUES (1002, 10, 1 JAN 2009');
INSERT INTO T_EMP_VISITS VALUES (1002, 30, 11 APR 2009');
INSERT INTO T_EMP_VISITS VALUES (1003, 20, 3 MAY 2009');
INSERT INTO T_EMP_VISITS VALUES (1003, 30: 14 FEB 2009');
COMMIT;
I have a T_EMP master table that stores the name and number of the emp. Each emp is required to visit some departments. This mapping is stored in the T_EMP_DEPT table. An employee can visit one or more departments. T_EMP_VISITS table stores the dates where the employee visited the services required. I need to view the report which should show when an employee all completed visits, which is the maximum date when it finished to visit all departments. If he did not visit any of the report should display date max, otherwise NULL. I was able to do using GROUP BY such proposed by Salim, but how do I show a list separated by commas of the services required for an employee in the same query.
SELECT
EMP_NO,
NAME,
MAX (DEPT_NO) KEEP (DENSE_RANK LAST ORDER BY VISITED) MAX_DEPT_NO,.
MAX (VISITED) KEEP (DENSE_RANK LAST ORDER PER VISIT) VISITS_COMP
DE)
SELECT
T_EMP. EMP_NO,
NAME,
T_EMP_DEPT. DEPT_NO,
VISITED
OF T_EMP
LEFT OUTER JOIN T_EMP_DEPT
ON T_EMP. EMP_NO = T_EMP_DEPT. EMP_NO
LEFT OUTER JOIN T_EMP_VISITS
ON T_EMP_DEPT. EMP_NO = T_EMP_VISITS. EMP_NO
AND T_EMP_DEPT. DEPT_NO = T_EMP_VISITS. DEPT_NO)
GROUP EMP_NO, NAME;
Output
EMP_NO NAME MAX_DEPT_NO VISITS_COMP
1001 MARK 20
1002 DAVID 20
1003 SHAUN 20 3 MAY 09
JILL 1004
Power required
EMP_NO NAME REQ_DEPTS MAX_DEPT_NO VISITS_COMP
1001 MARC 20 10.20
1002 DAVID 10,20,30 20
1003 SHAUN 20,30 20 3 MAY 09
JILL 10 1004
Can we do this in a single query?Hello
user512647 wrote:
... Sanjay
The query you provided that stragg() use seems to work but my requirement is not in the result set. I don't know how to use stragg with
MAX (DEPT_NO) KEEP (DENSE_RANK LAST ORDER BY VISITED) MAX_DEPT_NO,.
MAX (VISITED) KEEP (DENSE_RANK LAST ORDER PER VISIT) VISITS_COMP
I need more, these two columns these gives me the date when they have completed all visits. If they missed any Department then the result must be NULL in the VISITS_COMP field.Just add them to the SELECT clause:
SELECT t_emp.emp_no, name, STRAGG (t_emp_dept.dept_no) AS deptno, MAX (t_emp_dept.dept_no) KEEP (DENSE_RANK LAST ORDER BY visited) AS max_dept_no, MAX (visited) AS visits_comp FROM t_emp LEFT OUTER JOIN t_emp_dept ON t_emp.emp_no = t_emp_dept.emp_no LEFT OUTER JOIN t_emp_visits ON t_emp_dept.emp_no = t_emp_visits.emp_no AND t_emp_dept.dept_no = t_emp_visits.dept_no GROUP BY t_emp.emp_no , name ;
The column called visit_comp is simply the last visited, regardless of how the employee visited departments.
If you want to have the NULL value if the employee has not yet visited all 3 departments:... CASE WHEN COUNT (DISTINCT t_emp_dept.dept_no) = 3 THEN MAX (visited) END AS visits_comp
The 'magic number' 3 is the total number of departments.
If you want to understand the correct value of that at the time of the execution of the query, replace the code literal 3 hard with a scalar subquery.Note that 'KEEP MAX (x) (DENSE_RANK OVER LAST SERVICE BY x)' (where the exact same column is used as an argument and that the ORDER BY column) is just "MAX (x)".
-
Need to group by using a Table WITH
Hello
I use a database of XE 11.g. I have the following query, and it works. It generates the XML code for an email I send. I need to make a change. I think I need a group so I can can insert empty lines when the use_date_time field has changed in the output.
I put comment where I think that the Group By clause must go. When I try a comment this line and run the query, I get an ORA-00979: not a GROUP BY expression error.
Thanks for looking at this.
DECLARE
l_html_header varchar2 (1024);
CLOB l_html_body;
l_html_footer varchar2 (1024);
CLOB l_html_total;
BEGIN
l_html_body: = ' < div >
< table >
< b >
< tr / >
< th Width = "180" Align = "left" > mass Date time < /th >
< th Width = "100" Align = "left" > anthem Type < /th >
< th Width = "275" Align = "left" > name < /th > anthem
< th Width = "200" Align = "left" > definition < /th >
< th Width = "200" Align = "left" > < /th > interpreter
< /tr > ';
I'm in)
With html_table as)
Select hm.use_date_time
hm.use_type
hm.hymn_full_name
hm.gather_number
hm.setting
hm.performer
hm.use_type_key
Of HYMN_MAILING hm
order of use_date_time)
Select
use_date_time
use_type
hymn_full_name
gather_number
setting
interpreter
use_type_key
Html_table t
-Group By t.use_date_time
Order of t.use_date_time, t.use_type_key
) Loop
l_html_body: = l_html_body | "< tr >";
l_html_body: = l_html_body | "< td >" | TO_CHAR (i.use_date_time, ' MM/DD/YYYY HH: mi AM' ') | '< table > ";
l_html_body: = l_html_body | "< td >" | i.use_type | "< table >";
l_html_body: = l_html_body | "< td >" | i.hymn_full_name | "< table >";
l_html_body: = l_html_body | "< td >" | i.Setting | "< table >";
l_html_body: = l_html_body | "< td >" | i.performer | "< table >";
l_html_body: = l_html_body | "< /tr >";
end loop;
l_html_body: = l_html_body | '< /table > ';
l_html_header: = ' <! DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 / / IN" ""http://www.w3.org/TR/html4/strict.dtd"> ".
< html > < head > < title > anthem reminder < / title > < / head > < body > ';
l_html_footer: = ' < / div > < body / > < / html > ';
l_html_total: = l_html_header | l_html_body | l_html_footer;
dbms_output.put_line (l_html_total);
-html_email (p_to = > ' [email protected]', )
-- p_from => ' [email protected] ',
-p_subject = > 'Message of Test using subject and UTL_SMTP.
-p_text = > "This is a test message."
-p_html = > l_html_total,
-p_smtp_hostname = > "mail.site.org"
-p_smtp_portnum = > 587);
END;
/
Hello
I don't know what you want, either.
In pure SQL, you can use the GROUP BY ROLLUP to produce an additional line (called a Super row aggregate) at the end of each group.
However, given that you are using PL/SQL and stopping after each line, it is simpler test a change of value at that time here. (As a general rule, you want the back-end to retrieve data and nothing else. How do you present this data is best done by front end.)
For example, that you want to add a couple of
items between different values of use_date_time:DECLARE
prev_use_date_time html_table.use_date_time%TYPE;
l_html_header varchar2 (1024);
...
hm.hymn_full_name
-Joke the anthem:
-(Q) what was the name of Ralph Vaughn Williams's dog?
-(A) AMPNEY
...
) Loop
IF prev_use_date_time <> i.use_date_time
THEN
l_html_body: = l_html_body | '
';END IF;
prev_use_date_time: = i.use_date_time;
l_html_body: = l_html_body | '
'; ...
The rest of your code can remain unchanged.
-
Very Urgent: Setting dynamic where clause for Popup list VO
Hello world
It is a very urgent requirement please help as soon as possible.
I have a custom page in iSupplier. I created two supplier site, number of PO fields.
Site of beg - choice of Message and PO number - Message LOV of entry
I have a named VO under xxisupplier.oracle.apps.pos.home.poplist.server for site begging and xxisupplier.oracle.apps.pos.home.lov.server for PO number.
I have joined these two VO AM homepage.
Now the question is
1. I want to restrict these VO vendor_id-based so I'll put dynamically where clause for these two VO of in my CO
VO SITE PROVIDER QUERY
SELECT POVs.vendor_site_code site, pov.vendor_id
OF po_vendors pov, povs po_vendor_sites_all
WHERE pov.vendor_id = povs.vendor_id
AND TRUNC (povs.inactive_date) IS NULL
PO NUMBER LOV QUERY VO
SELECT DISTINCT ai.invoice_num, ai.vendor_id, ai.invoice_date, poh.segment1
AI ap_invoices_all,.
help ap_invoice_distributions_all,
po_headers_all poh,
po_distributions_all pda,
Al ap_lookup_codes
WHERE aid.po_distribution_id = pda.po_distribution_id
AND ai.invoice_id = aid.invoice_id
AND poh.po_header_id = pda.po_header_id
AND ai.invoice_type_lookup_code = al.lookup_code
AND al.lookup_type = 'INVOICE TYPE'
I am creating where cluase as below in CO
If (vendor_id1! = null)
{
System.out.println ("vendor_id:" + vendor_id1);
OAViewObjectImpl vo = (OAViewObjectImpl) am.findViewObject ("PO_LOV_VO");
if(vo!=null)
{
vo.clearCache ();
VO. Reset();
System.out.println ("inside IN. VO:" + vendor_id1);
vo.setWhereClause (null);
vo.setWhereClause ("vendor_id =: 1");
vo.setWhereClauseParams (null);
vo.setWhereClauseParam(0,vendor_id1);
vo.setOrderByClause ("invoice_date DESC");
String INVQRY = vo.getQuery ();
System.out.println ("INVQRY:" + INVQRY);
vo.executeQuery ();
VO. First();
System.out.println ("after the query appear" + vo.getRowCount ());
}
OAViewObjectImpl sitevo1 = (OAViewObjectImpl) am.findViewObject ("SUPPLIER_SITE_VO1");
if(sitevo1!=null)
{
sitevo1.clearcache ();
sitevo1. Reset();
System.out.println ("Interior site:" + vendor_id1);
sitevo1.setWhereClause (null);
sitevo1.setWhereClause ("vendor_id =: 1");
sitevo1.setWhereClauseParams (null);
sitevo1.setWhereClauseParam(0,vendor_id1);
String SITEQRY = sitevo1.getQuery ();
System.out.println ("SITEQRY:" + SITEQRY);
sitevo1. ExecuteQuery();
sitevo1. First();
System.out.println ("after the query appear" + sitevo1.getRowCount ());
}
Here he works for the purchase order number but the where cluase does not work for Supplier Site. Please help as soon as possible.
2 and also if supplier site to return multiple values then this field should show as messagechoice. If it returns a single value, then it should be the style text message
How can I achieve this.
Thank you
CSKTry
vo.setWhereClause ("IN vendor_id (" + vendor_id_qry + ")" ");
vendor_id_qry is the query that retrieves the list of provider IDS. You don't need to put the vendor column id as whereClauseParam unless you want to have IN the clause in your query of VO and pass the list as 1,2,3 values to the parameter.
Thank you
Shree -
Group by Clause displays all values search
Hello friends
I have a simple table with columns named Date, reason, product and County and the sample data are shown below.
==========================
Date reason product count
==========================
08/06/2012 raison1 home 1
08/07/2012 raison2 motor 1
08/08/2012 raison1 home 1
08/09/2012 Reason3 Home 2
08/10/2012 raison1 home 1
08/06/2012 Reason5 home 1
===========================
Altogether, I have 5 values of research through Reason5 raison1 reason, but few of them understand the table above.
I would like to diplay result per day and I will quote an example of August 6, I want to display the result below, i.e. show all reason 5 search and assign zero count if there are no records for this day there.
=====================================
DATE REASON HOME_COUNT MOTOR_COUNT
=====================================
08/06/2012 raison1 1-0
08/06/2012 0 1 raison2
08/06/2012 Reason3 0 0
08/06/2012 Reason4 0 0
08/06/2012 Reason5 1 0
=====================================
If we write group by clause, missing for reasons such as Reason3 Reason4 will not appear in the result set.
And I tried to write several UNION ALL queries to get the above result that works very well, but if it 100 search values, I don't want to write 100 Union queries.
Please let me know if you have analytical functions to display the results of the end?
Thank you
Murali.
Published by: Nathalie b on August 19, 2012 20:17If you followed relational design, you should lookup table. If you do not, you need to create a. In addition, date is reserved word, and the County is a key word, to not use as column names. Then, use the outer join:
SQL> create table tbl as 2 select to_date('06/08/2012','dd/mm/yyyy') dt,'Reason1' reason,'Home' product,1 qty from dual union all 3 select to_date('07/08/2012','dd/mm/yyyy'),'Reason2','Motor',1 from dual union all 4 select to_date('08/08/2012','dd/mm/yyyy'),'Reason1','Home',1 from dual union all 5 select to_date('09/08/2012','dd/mm/yyyy'),'Reason3','Home',2 from dual union all 6 select to_date('10/08/2012','dd/mm/yyyy'),'Reason1','Home',1 from dual union all 7 select to_date('06/08/2012','dd/mm/yyyy'),'Reason5','Home',1 from dual 8 / Table created. SQL> create table reason_list as 2 select 'Reason' || level reason from dual connect by level <= 5 3 / Table created. SQL> select d.dt, 2 r.reason, 3 nvl( 4 sum( 5 case product 6 when 'Home' then qty 7 end 8 ), 9 0 10 ) home_qty, 11 nvl( 12 sum( 13 case product 14 when 'Motor' then qty 15 end 16 ), 17 0 18 ) motor_qty 19 from ( 20 select min_dt + level - 1 dt 21 from ( 22 select min(dt) min_dt, 23 max(dt) max_dt 24 from tbl 25 ) 26 connect by level <= max_dt - min_dt + 1 27 ) d 28 cross join 29 reason_list r 30 left join 31 tbl t 32 on ( 33 t.dt = d.dt 34 and 35 t.reason = r.reason 36 ) 37 group by d.dt, 38 r.reason 39 order by d.dt, 40 r.reason 41 / DT REASON HOME_QTY MOTOR_QTY --------- ---------------------------------------------- ---------- ---------- 06-AUG-12 Reason1 1 0 06-AUG-12 Reason2 0 0 06-AUG-12 Reason3 0 0 06-AUG-12 Reason4 0 0 06-AUG-12 Reason5 1 0 07-AUG-12 Reason1 0 0 07-AUG-12 Reason2 0 1 07-AUG-12 Reason3 0 0 07-AUG-12 Reason4 0 0 07-AUG-12 Reason5 0 0 08-AUG-12 Reason1 1 0 DT REASON HOME_QTY MOTOR_QTY --------- ---------------------------------------------- ---------- ---------- 08-AUG-12 Reason2 0 0 08-AUG-12 Reason3 0 0 08-AUG-12 Reason4 0 0 08-AUG-12 Reason5 0 0 09-AUG-12 Reason1 0 0 09-AUG-12 Reason2 0 0 09-AUG-12 Reason3 2 0 09-AUG-12 Reason4 0 0 09-AUG-12 Reason5 0 0 10-AUG-12 Reason1 1 0 10-AUG-12 Reason2 0 0 DT REASON HOME_QTY MOTOR_QTY --------- ---------------------------------------------- ---------- ---------- 10-AUG-12 Reason3 0 0 10-AUG-12 Reason4 0 0 10-AUG-12 Reason5 0 0 25 rows selected. SQL>
SY.
-
can do without group by clause report through parameter
Hello expert,
I need to create a report in which the user select a field and adds this field in the group by clause of the sql query.
I know that the notion of setting lexical but getting only not the idea how the user for the group by clause...
I tried the following
Select trunc (m.spc_doc_date),
-d.spc_item_code,
Sum (NVL(d.req_qty,0)) x, sum (nvl(d.spc_item_qty,0)) y
of spc_ppc_daily_m m, spc_ppc_daily_d d
where m.spc_doc_ # in (select spc_doc_ # from spc_ppc_daily_m where fncl_year = 20112012)
and m.fncl_year = 20112012
and d.blce_qty > 0
and m.spc_locn_code = 400001
"and m.spc_doc_date between February 1, 2012'-February 29, 2012"
and m.spc_locn_code = d.spc_locn_code
and m.fncl_year = d.fncl_year
and m.spc_doc_ #= d.spc_doc_ #.
Group by & g_by
----------------------------
g_by is the report parameter
Thank you
Yoannyash_08031983 wrote:
Hello HamidBut when I compile my sql triggers Error statement due to & g_by or: g_by parameter.
Hello, yoann
Most likely, you are getting error ORA-00936 .
If the error above is true, then you are missing a part in sql.
First without lexical parameter your query should be ok. Correct your query without lexical parameter, and then add the lexical parameter.
Try thisselect trunc(m.spc_doc_date), --d.spc_item_code, sum(nvl(d.req_qty,0)) x,sum(nvl(d.spc_item_qty,0)) y from spc_ppc_daily_m m, spc_ppc_daily_d d where m.spc_doc_# in(select spc_doc_# from spc_ppc_daily_m where fncl_year=20112012) and m.fncl_year=20112012 and d.blce_qty>0 and m.spc_locn_code=400001 and m.spc_doc_date between '01-feb-2012' and '29-feb-2012' and m.spc_locn_code=d.spc_locn_code and m.fncl_year=d.fncl_year and m.spc_doc_#=d.spc_doc_# group by trunc(m.spc_doc_date) &g_by
Hope this helps...
Maybe you are looking for
-
Can I restore a single partition using the Toshiba Recovery disk?
I need to know if I can restore just the windows on my partition main because I don t want to format all my HARD drive.In my second partition I have backed up all my files and I don t want to erase.Please can someone tell if I can do this?
-
upper and lower filters in the registry how ca I get it back
in the registry, how can upper and lower filters I get them back. CD and dvd not being recognized
-
The function of scan from the HP Photosmart 7520 use a TWAIN-compatible driver
The function of scan from the HP Photosmart 7520 use a TWAIN-compatible driver
-
Data Execution Prevention prevents iTunes to launch... Any ideas?
A few days ago I stopped being able to launch iTunes. I immediately get a message sayign that he must close and Data Execution Prevention, it is that it is preventing from running. I'm on Vista and you have Service Pack 2.
-
K1 - sleep of death (Tablet don't wake up)
Well, pretty much what title says. I charge the Tablet, use it, it leaves about and when I try to use it, maybe in 2 days, it has no battery and it does not start when I press the power button. Do you know what happens? I was thinking about the insta