Rolling totals query ~ please help
I was stuck on a query for the last week. It would be amazing if someone could help me with this. nothing that I've done has worked so far. I have something after a few days ago and helped a little, but it works just the way I needed. This has been the more difficult application that I've ever worked on.
IM using oracle 11g.
What I'm trying to do, is get a bunch of aggregated values based on the dates of several projects running.
I made an export of the ddl for the current table and reviews, I wanted to not just after a sample of the data that it contains many records, and I think it's maybe easier to have the full extract.
Here is the link to the file http://santoro.us/pl_insert.sql
In the table I have IPS (which corresponds to a project id), create the full date, logged_date, status, date, due date (these are all the important columns)
What I'm trying to get a final result 1 table or 1 discovered that all totals accumulated per month for each project.
Here are the totals im looking to get
Open
Closed
open late
closed end
open closed punctually at the time
The thing is that I have to start the month by the project since the first month, that the project has a record. So if a first registration begins January 1, 2010 the project when the first album with totals should be 01/2010 and 02/2010, 03/2010, etc... until the current month. This must be done by project.
Thus, for example say there are only 2 projects (there are many others).
IPS 123
first record begins 01/01/2010
IPS 456
first record begins 01/01/2011
each have files that open and close on different dates in different months. Some might be late (complete date > expiration date), some closed on time (complete date < = due date).
end result would be a table that has:
Date | IPS | Open | closed | open late. closed end | opened on time. closed time |
01/2010 | 123 | 1. 0 | etc...
months would go completely to the current month
then start proj 2
01/2011 | 456. 1. 0 | etc...
months would go completely to the current month
each record would be counted from the date of creation of the document. As the records get late or closed (based on the due date, full date), then must be added/removed from the running of the data totals.
All this must be in 1 table or view. I know that some people might say it is the wrong way to do it, but that's how it should be done for the project im working on. IM generate xml at the end, so the developer needs him like that.
Yet once thanks for any help and please let me know if you need other information.
Thank you.
Earlier, I understand your condition. Try the below, it gives a correct output for FPS 100824. Check the other ips as well and let me know in case of any problems
WITH qry1 AS (SELECT ips,
ADD_MONTHS (trunc(min_date,'MM'),(Level-1)) act_date
FROM (SELECT MIN (create_date), min_date,
IPS
OF therm_punchlist
GROUP BY ips)
CONNECT BY LEVEL<=>=>
AND PRIOR ips = ips
AND PRIOR DBMS_RANDOM. VALUE IS NOT NULL)
SELECT TO_CHAR (act_date, 'MM-YYYY ',' NLS_DATE_LANGUAGE = ENGLISH') dt,
IPS,
Sum (open_cnt) OVER (PARTITION BY ips ORDER BY act_date)
-SUM (closed_cnt) OVER (PARTITION BY ips ORDER BY act_date) open_cnt,
Sum (closed_cnt) OVER (PARTITION BY ips ORDER BY act_date) closed_cnt,
CASE WHEN SUM (open_latecnt) OVER (PARTITION BY act_date ORDER BY act_date, ips) > 0 THEN
Sum (open_latecnt) OVER (PARTITION BY act_date ORDER BY act_date, ips)
-SUM (closed_cnt) OVER (PARTITION BY ips ORDER BY act_date)
ELSE SUM (open_latecnt) OVER (PARTITION BY act_date ORDER BY act_date, ips)
END as open_latecnt,
Sum (close_latecnt) OVER (PARTITION BY ips ORDER BY act_date) close_latecnt,
CASE WHEN SUM (open_latecnt) OVER (PARTITION BY act_date ORDER BY act_date, ips) > 0 THEN
Sum (open_ontimecnt) OVER (PARTITION BY ips ORDER BY act_date)
-Sum (open_latecnt) OVER (PARTITION BY act_date ORDER BY act_date, ips)
WHEN SUM (open_ontimecnt) OVER (PARTITION BY ips ORDER BY act_date) > 0 THEN
Sum (open_ontimecnt) OVER (PARTITION BY ips ORDER BY act_date)
-Sum (closed_cnt) OVER (PARTITION BY ips ORDER BY act_date)
ELSE SUM (open_ontimecnt) OVER (PARTITION BY ips ORDER BY act_date)
END as open_ontimecnt,
Sum (closed_ontimecnt) OVER (PARTITION BY ips ORDER BY act_date) closed_ontimecnt
FROM (SELECT act_date,
IPS,
(SELECT COUNT (*)
OF therm_punchlist tp
WHERE tp.ips = q1.ips
AND TRUNC (tp.create_date, 'MM') = act_date) open_cnt;
(SELECT COUNT (*)
OF therm_punchlist tp
WHERE tp.ips = q1.ips
AND TRUNC (tp.complete_date, 'MM') = act_date) closed_cnt;
(SELECT COUNT (CASE WHEN act_date > TRUNC(due_date,'MM') THEN status END))
OF therm_punchlist tp
WHERE tp.ips = q1.ips) open_latecnt;
(SELECT COUNT (CASE WHEN complete_date > end_date THEN status END))
OF therm_punchlist tp
WHERE tp.ips = q1.ips
AND TRUNC (tp.complete_date, 'MM') = act_date) close_latecnt;
(SELECT COUNT (CASE WHEN act_date<= trunc(due_date,'mm')="" then="" status="">=>
OF therm_punchlist tp
WHERE tp.ips = q1.ips) open_ontimecnt;
(SELECT COUNT (CASE WHEN complete_date<= due_date="" then="" status="">=>
OF therm_punchlist tp
WHERE tp.ips = q1.ips
AND TRUNC (tp.complete_date, 'MM') = act_date) closed_ontimecnt
OF qry1 q1);
Tags: Database
Similar Questions
-
My requirement is to calculate a few things like total_cash_amount, TOTAL_CO_PATIENT_AMOUNT etc... For this we will use BILLING. PATIENTBILL, BILLING. PATIENTBILLDETAILS, BILLING. Operating tables. Here it is already developed procedure.
I'm askd to change the same for best performance. This is the part of it that is calculation of total_cash_amount. There will be two categories such as INPATIENT (IP) and OUTPATIENT (OP). Can anyone of you please help me to change the code in a manner better. And can you please suggest that global temporary tables are better or can we use the tables directly.
Thanks in advance...INSERT INTO GTT_PATIENTBILL SELECT * FROM BILLING.PATIENTBILL P WHERE P.LOCATIONID = IN_LOCATIONID AND TRUNC(P.BILLDATE) BETWEEN TRUNC(IN_YEARDATE) AND TRUNC(IN_FROMDATE); INSERT INTO GTT_PATIENTBILLDETAILS SELECT PB.* FROM BILLING.PATIENTBILL P, BILLING.PATIENTBILLDETAILS PB WHERE P.LOCATIONID = IN_LOCATIONID AND P.BILLNO = PB.BILLNO AND TRUNC(P.BILLDATE) BETWEEN TRUNC(IN_YEARDATE) AND TRUNC(IN_FROMDATE); INSERT INTO GTT_TRANSACTION SELECT * FROM BILLING.TRANSACTION T WHERE T.LOCATIONID = IN_LOCATIONID AND TRUNC(T.CREATEDDATE) BETWEEN TRUNC(IN_YEARDATE) AND TRUNC(IN_FROMDATE); DELETE FROM TEMP_1; INSERT INTO TEMP_1 SELECT (CASE WHEN PARTICULARS IS NULL AND FLG = 1 THEN 'TOTAL COLLECTIONS' WHEN PARTICULARS IS NULL AND FLG = 2 THEN 'TOTAL DEDUCTIONS' ELSE PARTICULARS END) PARTICULARS, SUM(A) "FOR THE DAY", SUM(B) "MONTH TO DATE", SUM(C) "YEAR TO DATE" FROM (SELECT PARTICULARS, SUM(TOTAL_CASH_AMOUNT_DAY) A, SUM(TOTAL_CASH_AMOUNT_MONTH) B, SUM(TOTAL_CASH_AMOUNT_YEAR) C, 1 FLG FROM (SELECT 'OP CASH' PARTICULARS, SUM(P.TOTALSERVICEAMOUNT) TOTAL_CASH_AMOUNT_DAY, 0 TOTAL_CASH_AMOUNT_MONTH, 0 TOTAL_CASH_AMOUNT_YEAR FROM GTT_PATIENTBILL P--BILLING.PATIENTBILL P, BILLING.PATIENTBILLDETAILS PB WHERE P.LOCATIONID = IN_LOCATIONID --AND P.BILLNO = PB.BILLNO AND P.BILLINGTYPEID = 1 AND P.PATIENTSERVICE = 2 AND TRUNC(P.BILLDATE) =TRUNC(IN_FROMDATE) UNION ALL SELECT 'OP CASH' PARTICULARS, 0, SUM(P.TOTALSERVICEAMOUNT) TOTAL_CASH_AMOUNT_MONTH, 0 FROM GTT_PATIENTBILL P--BILLING.PATIENTBILL P, BILLING.PATIENTBILLDETAILS PB WHERE P.LOCATIONID = IN_LOCATIONID --AND P.BILLNO = PB.BILLNO AND P.BILLINGTYPEID = 1 AND P.PATIENTSERVICE = 2 AND TRUNC(P.BILLDATE) BETWEEN TRUNC(IN_MONTHDATE) AND TRUNC(IN_FROMDATE) UNION ALL SELECT 'OP CASH' PARTICULARS, 0, 0, SUM(P.TOTALSERVICEAMOUNT) TOTAL_CASH_AMOUNT_YEAR FROM GTT_PATIENTBILL P--BILLING.PATIENTBILL P, BILLING.PATIENTBILLDETAILS PB WHERE P.LOCATIONID = IN_LOCATIONID --AND P.BILLNO = PB.BILLNO AND P.BILLINGTYPEID = 1 AND P.PATIENTSERVICE = 2 AND TRUNC(P.BILLDATE) BETWEEN TRUNC(IN_YEARDATE) AND TRUNC(IN_FROMDATE) UNION ALL SELECT 'IP CASH' PARTICULARS, SUM(P.TOTALSERVICEAMOUNT) TOTAL_CASH_AMOUNT_DAY, 0 TOTAL_CASH_AMOUNT_MONTH, 0 TOTAL_CASH_AMOUNT_YEAR FROM GTT_PATIENTBILL P--BILLING.PATIENTBILL P, BILLING.PATIENTBILLDETAILS PB WHERE P.LOCATIONID = IN_LOCATIONID --AND P.BILLNO = PB.BILLNO AND P.BILLINGTYPEID = 1 AND P.PATIENTSERVICE = 3 AND TRUNC(P.BILLDATE) = TRUNC(IN_FROMDATE) UNION ALL SELECT 'IP CASH' PARTICULARS, 0, SUM(P.TOTALSERVICEAMOUNT) TOTAL_CASH_AMOUNT_MONTH, 0 FROM GTT_PATIENTBILL P--BILLING.PATIENTBILL P, BILLING.PATIENTBILLDETAILS PB WHERE P.LOCATIONID = IN_LOCATIONID --AND P.BILLNO = PB.BILLNO AND P.BILLINGTYPEID = 1 AND P.PATIENTSERVICE = 3 AND TRUNC(P.BILLDATE) BETWEEN TRUNC(IN_MONTHDATE) AND TRUNC(IN_FROMDATE) UNION ALL SELECT 'IP CASH' PARTICULARS, 0, 0, SUM(P.TOTALSERVICEAMOUNT) TOTAL_CASH_AMOUNT_YEAR FROM GTT_PATIENTBILL P--BILLING.PATIENTBILL P, BILLING.PATIENTBILLDETAILS PB WHERE P.LOCATIONID = IN_LOCATIONID --AND P.BILLNO = PB.BILLNO AND P.BILLINGTYPEID = 1 AND P.PATIENTSERVICE = 3 AND TRUNC(P.BILLDATE) BETWEEN TRUNC(IN_YEARDATE) AND TRUNC(IN_FROMDATE)) T1 GROUP BY PARTICULARS
You can do this in the same query. As long as the underlying table is the same thing that you don't have to have multiple queries to the same table. You just improvise on your selection fields. Use a CASE statement instead of DECIDING that I used and include the other INDICATIONS which I didn't understand.
-
need help with query-please help
Hi all
I want to convert the query to a view online below. I write examples of data that I used
Please help mecreate table pde(empno number(10),act_hour varchar(10 byte)); Table created insert into pde values(211,'12:20'); insert into pde values(211,'06:00'); insert into pde values(213,'07:00'); insert into pde values(213,'07:20'); WITH got_total_hours AS ( SELECT SUM ( TO_NUMBER (SUBSTR (act_hour, 1, 2)) + ( TO_NUMBER (SUBSTR (act_hour, 4, 2)) / 60 ) ) AS total_hours from pde ) SELECT TO_CHAR (FLOOR (total_hours)) || ':' || TO_CHAR ( MOD (total_hours, 1) * 60 , 'fm00' ) AS hh_mm,empno,act_hour FROM got_total_hours ,pde this is the output i am getting HH_MM EMPNO ACT_HOUR 32:40 211 12:20 32:40 211 06:00 32:40 213 07:00 32:40 213 07:20 i tried changing the above query to an inline view given below SELECT TO_CHAR (FLOOR (total_hours)) || ':' || TO_CHAR ( MOD (total_hours, 1) * 60 , 'fm00' ) AS hh_mm,act_hour from(SELECT SUM ( TO_NUMBER (SUBSTR (act_hour, 1, 2)) + ( TO_NUMBER (SUBSTR (act_hour, 4, 2)) / 60 ) ) AS total_hours from pde) ORA-00904:''ACT_HOUR":invalid identifier
thanking in advance
Kind regards
oracleuser
Published by: makdutakdu on January 5, 2010 11:41Just push "with the clause" within the main request and give an alias of the table for him... something like
SELECT TO_CHAR (FLOOR (total_hours)) || ':' || TO_CHAR ( MOD (total_hours, 1) * 60 , 'fm00' ) AS hh_mm, empno , act_hour FROM (SELECT SUM ( TO_NUMBER (SUBSTR (act_hour, 1, 2)) + ( TO_NUMBER (SUBSTR (act_hour, 4, 2)) / 60 ) ) AS total_hours FROM pde ) got_total_hours , pde
Ravi Kumar
-
only one sql query - please help
Hi experts,
what I want to do is to write a single application that will show if an employee
outputs in the company or not. I have two tables emp and Dept. There are as follows.
SQL > select * from emp;
NAME DEPTNO EMPNO
------- ---------- ----------
10 33036 xxx
12 2345 YYY
ZZZ 13 678
14 5678 KKK
RRR 15 7865
SQL > select * from the Department;
DEPTNO LOCATION
---------- ------------------------------
10 AAA
BBB 11
12 CCC
13 DDD
what I want is she will select records in the emp table and find out if corrosponding
DeptNo is actually in the dept table. If the value is found in the dept table deptno column then it will set the value
Y other wise it will be and what should I do with the help of a single request.
expected result
empno name exists
XXX 33036 Y
YYY 2345 Y
ZZZ 678 Y
KKK 5678 N
7865 N RRR
Help, please.
Concerning
RajatSELECT EMPNO, NAME , EMPNO , NVL( ( SELECT 'Y' FROM DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO),'N') EXIST FROM EMP ORDER BY 1
Demo
SQL> WITH EMP AS( 2 SELECT 'XXX' NAME , 10 DEPTNO ,33036 EMPNO FROM DUAL UNION 3 SELECT 'YYY', 12, 2345 FROM DUAL UNION 4 SELECT 'ZZZ', 13 ,678 FROM DUAL UNION 5 SELECT 'KKK', 14 ,5678 FROM DUAL UNION 6 SELECT 'RRR', 15 ,7865 FROM DUAL ), 7 DEPT AS( 8 SELECT 10 DEPTNO,'AAA' DNAME FROM DUAL UNION 9 SELECT 11 ,'BBB' FROM DUAL UNION 10 SELECT 12 ,'CCC' FROM DUAL UNION 11 SELECT 13 ,'DDD'FROM DUAL ) 12 SELECT EMPNO, NAME , EMPNO , NVL( ( SELECT 'Y' FROM DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO),'N') EXIST 13 FROM EMP 14 ORDER BY 1 15 / EMPNO NAM EMPNO E ---------- --- ---------- - 678 ZZZ 678 Y 2345 YYY 2345 Y 5678 KKK 5678 N 7865 RRR 7865 N 33036 XXX 33036 Y SQL>
Published by: Salim champion on December 7, 2008 04:15
-
BlackBerry Z30 please help me in a big mess
My z10 told me restart the phone because my videos where not not opening after the reboot happened to show ing just the name from blackberry to the red light, then he turned completely off, help pleease cos it is a phone friend birthday is today, and I've totally ruined, please help
This article might help you.
It is not, you can claim a warranty or take it to a phone repair specialist.
Good luck.
-
I have some problem in my query to sql server. If I press f5 to run it opens to record dialogue area nd do not run (I don't get successful... orders etc). Please help me
Hello
SQL Server is not supported in these forums. I suggest that you ask your question again in one of the forums dedicated to Microsoft for him here:
http://social.technet.microsoft.com/Forums/en-us/category/sqlserver .
Thank you. :)
-
Please help me find the solution for the query
Hi Experts,
Please help build a sql query. Thank you
Examples of data
-------------------
create the table Material_tb
(
Detail varchar2 (20).
Description varchar2 (200)
)
/
Start
Insert into material_tb values('Color','Red,Blue,Black,Green,White');
Insert into material_tb values ('Material','Gold, Silver, Platinum');
end;
/
Select * from material_tb;
DETAIL DESCRIPTION
-------------------- ------------------------------
Color red, blue, black, green, white
Material gold, silver, Platinum
I want that output voltage
DETAIL DESCRIPTION
-------------------- ------------------------------
Red color
Blue color
Black color
Green color
White color
Material gold
Silver material
Platinum material
You can try under sql
select distinct detail,regexp_substr(description,'[^,]+',1,LEVEL) from material_tb connect by regexp_substr(description,'[^,]+',1,LEVEL) is not null order by 1
-
Hello
Please help build a sql query
My Table Test2015 has given belowHeader_id Line_id Ordered_item
723887290 199925 MAIN1
199925 723887291 MAIN2
199926 723887292 SH-POS-NO-BR POS-INS
199926 723887293 MAIN2
199927 723887294 IC-ENV-NON-BR-ENV-PXY
199927 723887295 MAIN1
199927 723887297 MAIN2
199927 723887298 PRCSS SH-FAIRY-ELEC DISTR.
199927 723887299 SH-FAIRY-SUM PRO-DE-CONS-HOUSE
I am trying to query my Test2015 table to obtain the records with ordered_item containing 'MAIN1' and 'MAIN2' only. I tried to write a query as below
SELECT * FROM test2015 WHERE ORDERED_ITEM in ('MAIN1', 'MAIN2');
But it gives me all the data with the MAIN2 records found but MAIN1 is absent, I want to retrieve only records to both 'MAIN1' and 'MAIN2' present for Header_id.
While the result below shows me header_id - 199926 and 199929 that he should assume back. I want to fetch documents only with 'MAIN1' and 'MAIN2' both present.
Header_id Line_id Ordered_item
723887290 199925 MAIN1
199925 723887291 MAIN2
199926 723887293 MAIN2
199927 723887295 MAIN1
199927 723887297 MAIN2
199929 723887299 MAIN1
Please suggest.
Thank you and best regards,
Prasad.
Hello
Try like this...
SELECT * FROM test2015 WHERE ORDERED_ITEM in ('MAIN1") and in header_id (select test2015 WHERE ORDERED_ITEM in ('MAIN2') header_id)
-
Ask help - please help me get the expected defined in a query result
Dear all,
Help with your suggestions and advice. Please see the bottom of the screenshots for the planned result sets.
create table shift_dt (name varchar2(20), shift_start date, shift_end date); insert into shift_dt values ('Brian',to_date('01-01-2015 09:10:00','dd-mm-yyyy hh24:mi:ss'), to_date('01-01-2015 22:10:00','dd-mm-yyyy hh24:mi:ss')); insert into shift_dt values ('Brian',to_date('02-01-2015 09:10:00','dd-mm-yyyy hh24:mi:ss'), to_date('04-01-2015 00:00:00','dd-mm-yyyy hh24:mi:ss')); insert into shift_dt values ('Brian',to_date('04-01-2015 00:00:00','dd-mm-yyyy hh24:mi:ss'), to_date('05-01-2015 15:20:00','dd-mm-yyyy hh24:mi:ss')); insert into shift_dt values ('Brian',to_date('06-01-2015 10:00:00','dd-mm-yyyy hh24:mi:ss'), to_date('06-01-2015 23:20:00','dd-mm-yyyy hh24:mi:ss')); insert into shift_dt values ('Brian',to_date('07-01-2015 11:00:00','dd-mm-yyyy hh24:mi:ss'), to_date('09-01-2015 00:00:00','dd-mm-yyyy hh24:mi:ss')); insert into shift_dt values ('Brian',to_date('09-01-2015 00:00:00','dd-mm-yyyy hh24:mi:ss'), to_date('10-01-2015 22:00:00','dd-mm-yyyy hh24:mi:ss')); select * from shift_dt;
Select * from shift_dt;
Expected result set: -.
I compare date of shift_end with the next date of shift_start of the day. If the dates made 12 am (IE 00:00:00), then I ignore and display the next shift end date available as displayed in the screen game result. Please see the screen set outcome turned for more details.
Please help get the results you want in the SQL query
Kind regards
Souls
Hello
Here's one way:
WITH got_new_grp AS
(
SELECT name, shift_start, shift_end
CASE
WHEN shift_start = TRUNC (shift_start)
AND shift_start = LAG (shift_end) OVER (ORDER BY shift_start)
THEN 0
1. OTHER
END AS new_grp
OF shift_dt
)
got_grp AS
(
SELECT name, shift_start, shift_end
SUM (new_grp) OVER (ORDER BY shift_start) AS grp
OF got_new_grp
)
SELECT MIN (name) DUNGEON (DENSE_RANK FIRST ORDER BY shift_start)
As a name
MIN (shift_start) AS shift_start
MAX (shift_end) AS shift_end
OF got_grp
GROUP BY grp
ORDER BY shift_start
;
Output (from the full sample data):
NAME SHIFT_START SHIFT_END
-------------------- ---------------- ----------------
01/01/2015 Brian 09:10 01/01/2015 22:10
Brian 02/01/2015 09:10 01/05/2015 15:20
Brian 06/01/2015 10:00 01/06/2015 23:20
Brian 07/01/2015 11:00 10/01/2015 22:00
Brian 01/02/2015 15:00 02/02/2015 00:00
Brian 02/02/2015 11:00 02/02/2015 17:00
Brian 03/02/2015 00:00 03/02/2015 08:00
Brian 02/05/2015 15:30 06/02/2015 07:30
Brian 07/02/2015 23:30 10/02/2015 00:30
I guess that shift_start is unique.
It's finally a GROUP BY problem: we want to show the first shift_start and the last shfit_end of a group of 1 or more lines. The tricky part is to identify the groups. If I understand the problem, line X is grouped with the previous line X-1 if shift_start on the X line is midnight and is equal to shift_end on line X-1. The above query uses the LAG analytic to see if each line begins a new group or not and the analytic function SUM to see how many groups have already begun (and therefore, which group each line entry belongs.)
I still don't understand why you 'Corrected name of Anne in Brian' and not vice versa. I guess the name to display in each group is the name of the first row in the Group (i.e. the line with the shift_start earlier).
-
I have the data into two table with the structure of similar column, I want to loop through the data in these two tables
based on some condition and runtime that I want to put the query in loop for example, the example is given, please help me
create table ab (a number, b varchar2 (20));
Insert into ab
Select rownum, rownum. "" sample "
of the double
connect by level < = 10
create table bc (a number, b varchar2 (20));
Insert into BC.
Select rownum + 1, rownum + 1 | "" sample "
of the double
connect by level < = 10
declare
l_statement varchar2 (2000);
Boolean bool;
Start
bool: = true;
If it is true, then
l_statement: =' select * ab ';
on the other
l_statement: =' select * from bc';
end if
I'm in execute immediate l_statement - something like that, but I don't know
loop
dbms_output.put_line (i.a);
end loop;
end;
Something like that, but this isn't a peace of the code work.
Try this and adapt according to your needs:
declare
l_statement varchar2 (2000);
c SYS_REFCURSOR;
l_a number;
l_b varchar2 (20);
Boolean bool;
Start
bool: = true;
If it is true, then
l_statement: = "select a, b, AB;
on the other
l_statement: = "select a, b from bc;
end if;
--
Open c for l_statement;
--
loop
extract the c in l_a, l_b;
When the output c % notfound;
dbms_output.put_line (l_a |') -' || l_b);
end loop;
close c;
end;
/
-
Please, help me to query SQL Construct.
Hi Experts,Could you please help me to query SQL Construct. Please find the details
HOSTNAME HOSTTYPE DEM R1 R2
RS123 P ABC 24.5 265,5RS123 P CYC 24.5 265,5
RS123 P ADDS 24.5 265,5
RS123 P ADE 24.5 265,5
RS123 P SRC 24.5 265,5
EXPECTED RESULTS
HOSTNAME HOSTTYPE MNE R1 R2
RS123 P ABC, CYC, ADD, ADE, CBC 24.5 265,5Concerning
See you soon
with t as)
Select "RS123' hostname 'P' hosttype, 'ABC' dem, 24.5 r1, r2 265,5 Union double all the
Select 'RS123', 'P', "CYC", 24.5, 265,5 double Union all
Select 'RS123', 'P', 'ADD', 24.5, 265,5 double Union all
Select "RS123', 'P', 'ADE', 24.5, 265,5 double Union all
Select 'RS123', 'P', 'SRC', 24.5, 265,5 double
)
Select the host name,
HostType,
RTrim (XMLAGG (XmlElement(e,MNE,','). (Extract ('//Text ()')), ',') DEM,.
R1,
R2
t
Group hostname,
HostType,
R1,
R2
/
HOSTN H DEM R1 R2
----- - -------------------- ---------- ----------
RS123 P ABC, CBC, ADE, ADD, CYC 24.5 265,5SQL >
SY.
-
Query XML giving NULL result - please help!
Hello
I am a newbie in XML and I try to extract the XMLType column information.
I am using Oracle 11g
I use the table is
CREATE TABLE 'PRODUCTS '.
(
'ID' VARCHAR2 (10 BYTE),
"CUSTDOC" 'SYS '. "" XMLTYPE.
)
_________________________________________________________________
I am the slot loading XML file in the CUSTDOC column
< report xmlns = "http://developer.cognos.com/schemas/report/6.0/."
expressionLocale = "en - to the" >
[< modelPath > / content/folder[@name='Packages']/folder[@name='Prod']/package[@name='ORGS']/model[@name='model'] < / modelPath >
< drillBehavior modelBasedDrillThru = "true" / >
< query >
< application name = "Query1" >
< source >
< model / >
< / source >
< selection >
< name of dataItem = aggregate 'Incident ID' = 'none' rollupAggregate = 'none' >
< expression > [ABC]. [XYZ]. [Incident] < / expression >
< / dataItem >
< / selection >
< detailFilters >
< detailFilter >
< filterExpression > [ABC]. [XYZ]. [Company] = "SOCIÉTÉTEST" < / filterExpression >
< / detailFilter >
< / detailFilters >
< / query >
< / queries >
< layouts >
< layout >
< reportPages >
< name = 'Page1' page >
< style >
< defaultStyles >
< defaultStyle = "pg" refStyle / >
< / defaultStyles >
< / style >
< pageBody >
< style >
< defaultStyles >
< defaultStyle = "pb" refStyle / >
< / defaultStyles >
< / style >
< content >
< refQuery list = "Query1" horizontalPagination = "true" name = "List1" >
< style >
< defaultStyles >
< defaultStyle = 'ls' refStyle / >
< / defaultStyles >
< value CSS = "border-collapse: collapse" / >
< / style >
< more >
< listColumn >
< listColumnTitle >
< style >
< defaultStyles >
< defaultStyle = 'lt' refStyle / >
< / defaultStyles >
< / style >
< content >
< textItem >
< dataSource >
< dataItemLabel refDataItem = "The Incident ID" / >
< / dataSource >
< / textItem >
< / Summary >
< / listColumnTitle >
< listColumnBody >
< style >
< defaultStyles >
< defaultStyle = 'lc' refStyle / >
< / defaultStyles >
< / style >
< content >
< textItem >
< dataSource >
< dataItemValue refDataItem = "The Incident ID" / >
< / dataSource >
< / textItem >
< / Summary >
< / listColumnBody >
< / listColumn >
< / more >
< / list >
< / Summary >
< / pageBody >
< Entetepage >
< content >
< block >
< style >
< defaultStyles >
< defaultStyle = 'ta' refStyle / >
< / defaultStyles >
< / style >
< content >
< textItem >
< style >
< defaultStyles >
< defaultStyle = "tt" refStyle / >
< / defaultStyles >
< / style >
< dataSource >
< staticValue / >
< / dataSource >
< / textItem >
< / Summary >
< / block >
< / Summary >
< style >
< defaultStyles >
< defaultStyle = "ph" refStyle / >
< / defaultStyles >
< value = CSS "padding-bottom: 10px" / >
< / style >
< / pageHeader >
< pageFooter >
< content >
< table >
< tableRows >
< tableRow >
< tableCells >
< tableCell >
< content >
< date >
< style >
< dataFormat >
< dateFormat / >
< / dataFormat >
< / style >
< / date >
< / Summary >
< style >
< value="vertical-align:top;text-align:left;width:25%"/ CSS >
< / style >
< / tableCell >
< tableCell >
< content >
< pageNumber / >
< / Summary >
< style >
< value="vertical-align:top;text-align:center;width:50%"/ CSS >
< / style >
< / tableCell >
< tableCell >
< content >
< time >
< style >
< dataFormat >
< timeFormat / >
< / dataFormat >
< / style >
< / time >
< / Summary >
< style >
< value="vertical-align:top;text-align:right;width:25%"/ CSS >
< / style >
< / tableCell >
< / tableCells >
< / tableRow >
< / TableRow >
< style >
< defaultStyles >
< defaultStyle = "CT" refStyle / >
< / defaultStyles >
< value="border-collapse:collapse;width:100%"/ CSS >
< / style >
< /table >
< / Summary >
< style >
< defaultStyles >
< defaultStyle = "pf" refStyle / >
< / defaultStyles >
< value = CSS "padding-top: 10px" / >
< / style >
< / pageFooter >
< / print this page >
< / reportPages >
< / page layout >
< / page layout >
< XMLAttributes >
< name XMLAttribute = "RS_CreateExtendedDataItems" value = "true" output = "no" / >
< name XMLAttribute = "listSeparator' value = ',' output ="no"/ >
< / XMLAttributes >
< / report >
____________________________________________________________________________________
I run the query below
SELECT SYS. XMLTYPE. GETCLOBVAL (SYS. XMLTYPE. Extract ("CUSTDOC",'/ Report/Queries/Query/Selection/DataItem/expression / Text () ')) 'CUSTDOC' OF 'PRODUCT '.
and I await the result below
CUSTDOC
---
[ABC]. [XYZ]. [Incident]
but I am NOTHING.
Please help me. Don't know what I'm doing wrong here.
Kind regards
RaviHi Ravi,
Don't know what I'm doing wrong here.
Two things:
-EXTRACT function is deprecated--> use XMLQuery or XMLTable rather
-You are missing the namespace declarationSee if it works for you:
SQL> SELECT XMLCast( 2 XMLQuery( 3 'declare default element namespace "http://developer.cognos.com/schemas/report/6.0/"; (: :) 4 /report/queries/query/selection/dataItem/expression' 5 passing t.custdoc 6 returning content 7 ) 8 as varchar2(30) 9 ) as expr 10 FROM product t ; EXPR ------------------------------ [ABC].[XYZ].[Incident]
-
Hello
We have two tables test_a and test_b and would like to get the result of this query:
COL1 VAL_A VAL_B
------------------------------ ------------------------------ -------------
code_1 aa_1 aa_1
code_1 aa_2 aa_2
code_1 aa_3
code_2 bb_1
code_2 bb_2
Could someone please help on this, thanks a lot!
create table test_a)
col1 varchar2 (30),
col2 varchar2 (30));
insert into values test_a ('code_1', 'aa_1');
insert into values test_a ('code_1', 'aa_2');
insert into values test_a ('code_1', 'aa_3');
insert into test_a values ('code_2', 'bb_1');
commit;
create table test_b)
col1 varchar2 (30),
col2 varchar2 (30));
insert into test_b values ('code_1', 'aa_1');
insert into test_b values ('code_1', 'aa_2');
insert into test_b values ('code_2', 'bb_2');
commit;
Select * from test_a;
COL1 COL2
------------------------------ ------------------------------
code_1 aa_1
code_1 aa_2
code_1 aa_3
code_2 bb_1
Select * from test_b;
COL1 COL2
------------------------------ ------------------------------
code_1 aa_1
code_1 aa_2
code_2 bb_2
Published by: user489948 on January 5, 2010 10:13
Published by: user489948 on January 5, 2010 10:15
-
Please help me write this SQL query...
Thanks in advanceHi everyone, Please help me in this query. A patient can multiple types of Adresses (types P,M,D).If they have all the 3 types i need to select type: p and if they have (M and D) i need to select type M,and if they have only type D i have to select that. For each address i need to validate whether that particular address is valid or not (by start date and end date and valid flag) Patient table ============= Patient_id First_name last_name 1 sanjay kumar 2 ajay singh 3 Mike John Adress table ============ address_id patient_id adresss city type startdate enddate valid_flg 1 1 6222 dsadsa P 01/01/2007 01/01/2010 2 1 63333 dsad M 01/02/2006 01/01/2007 N 3 1 64564 fdf M 01/01/2008 07/01/2009 4 1 654757 fsdfsa D 01/02/2008 09/10/2009 5 2 fsdfsd fsdfsd M 01/03/2007 09/10/2009 6 2 jhkjk dsad D 01/01/2007 10/10/2010 7 3 asfd sfds D 01/02/2008 10/10/2009 output ===== 1 sanjay kumar 6222 dsadsa P 01/01/2007 01/01/2010 2 ajay singh fsdfsd fsdfsd M 01/03/2007 09/10/2009 3 mike john asfd sfds D 01/02/2008 10/10/2009
PhaniHello, Fabienne,.
This race for you (twisted code of Sarma):
SELECT patient_id, first_name, last_name, address, city, type, startdate, enddate FROM ( SELECT a.patient_id patient_id, first_name, last_name, address, city, type, startdate, enddate, ROW_NUMBER() OVER (PARTITION BY p.patient_id ORDER BY CASE type WHEN 'P' THEN 1 WHEN 'M' THEN 2 WHEN 'D' THEN 3 END) rn FROM patient p JOIN address a ON (p.patient_id = a.patient_id ) WHERE NVL(valid_flg, 'X') != 'N' AND SYSDATE BETWEEN startdate AND NVL(enddate, SYSDATE) ) WHERE rn = 1;
Edit, currently in the trial:
With Patient AS ( SELECT 1 Patient_id , 'sanjay' First_name, 'kumar' last_name FROM DUAL UNION ALL SELECT 2, 'ajay', 'singh' FROM DUAL UNION ALL SELECT 3, 'Mike', 'John' FROM DUAL), Address AS ( SELECT 1 address_id, 1 patient_id, '6222' address, 'dsadsa' city, 'P' type, to_date('01/01/2007', 'DD/MM/YYYY') startdate, to_date('01/01/2010', 'DD/MM/YYYY') enddate, NULL valid_flg FROM DUAL UNION ALL SELECT 2,1,'63333','dsad','M', to_date('01/02/2006', 'DD/MM/YYYY'), to_date('01/01/2007', 'DD/MM/YYYY'), ' N' FROM DUAL UNION ALL SELECT 3,1,'64564','fdf','M', to_date('01/01/2008', 'DD/MM/YYYY'), to_date('07/01/2009', 'DD/MM/YYYY'), NULL FROM DUAL UNION ALL SELECT 4,1,'654757','fsdfsa','D', to_date('01/02/2008', 'DD/MM/YYYY'), to_date('09/10/2009', 'DD/MM/YYYY'), NULL FROM DUAL UNION ALL SELECT 5,2,'fsdfsd ','fsdfsd','M', to_date('01/03/2007', 'DD/MM/YYYY'), to_date('09/10/2009', 'DD/MM/YYYY'), NULL FROM DUAL UNION ALL SELECT 6,2,' jhkjk','dsad','D', to_date('01/01/2007', 'DD/MM/YYYY'), to_date('10/10/2010', 'DD/MM/YYYY'), NULL FROM DUAL UNION ALL SELECT 7,3,'asfd',' sfds',' D', to_date('01/02/2008', 'DD/MM/YYYY'), to_date('10/10/2009', 'DD/MM/YYYY'), NULL FROM DUAL) -- end test data SELECT patient_id, first_name, last_name, address, city, type, startdate, enddate FROM ( SELECT a.patient_id patient_id, first_name, last_name, address, city, type, startdate, enddate, ROW_NUMBER() OVER (PARTITION BY p.patient_id ORDER BY CASE type WHEN 'P' THEN 1 WHEN 'M' THEN 2 WHEN 'D' THEN 3 END) rn FROM patient p JOIN address a ON (p.patient_id = a.patient_id ) WHERE NVL(valid_flg, 'X') != 'N' AND SYSDATE BETWEEN startdate AND NVL(enddate, SYSDATE) ) WHERE rn = 1; PATIENT_ID FIRST_ LAST_ ADDRESS CITY TY STARTDATE ENDDATE ---------- ------ ----- ------- ------ -- --------- --------- 1 sanjay kumar 6222 dsadsa P 01-JAN-07 01-JAN-10 2 ajay singh fsdfsd fsdfsd M 01-MAR-07 09-OCT-09 3 Mike John asfd sfds D 01-FEB-08 10-OCT-09
-
Reg: Query writing - please help
Hello
can you please help me get the results below?
select * from emp_time EMP_ID SHIFT_START_TIME SHIFT_END_TIME YARD_DEPARTURE EFFECTIVE_DATE 220541 03-12-08 03-12-08 y 03-12-08 220541 04-12-08 04-12-08 y 04-12-08 220541 18-02-09 18-02-09 y 18-02-09 220541 20-02-09 20-02-09 y 20-02-09 220541 24-02-09 24-02-09 y 24-02-09 220541 25-02-09 25-02-09 y 25-02-09 220541 26-02-09 26-02-09 y 26-02-09 220541 27-02-09 27-02-09 y 27-02-09 220541 28-02-09 28-02-09 y 28-02-09 220541 28-03-09 28-03-09 y 28-03-09 select * from emp_time where effective_date between to_date('02-20-09','mm-dd-yy') and to_date('02-24-09','mm-dd-yy'); EMP_ID SHIFT_START_TIME SHIFT_END_TIME YARD_DEPARTURE EFFECTIVE_DATE 220541 20-02-09 20-02-09 y 20-02-09 220541 24-02-09 24-02-09 y 24-02-09 Expected output: EMP_ID SHIFT_START_TIME SHIFT_END_TIME YARD_DEPARTURE EFFECTIVE_DATE 220541 20-02-09 20-02-09 y 20-02-09 220541 20-02-09 20-02-09 y 21-02-09 220541 20-02-09 20-02-09 y 22-02-09 220541 20-02-09 20-02-09 y 23-02-09 220541 24-02-09 24-02-09 y 24-02-09
Oracle Version: 11.2.0
Kind regards
Jame
Let me make a try also, because your statement only a min and max on XX, efective_date whatever the emp_id ;-)
I pretend not, this one is better (too many results that must be filtered with a separate), but it should be emp id independent
with emp_exist as (select emp_id
shift_start_time
shift_end_time
yard_departure
effective_date
of emp_time)
emp_fake as (select emp_id separate
to_date('02-20-09','mm-dd-yy') shift_start_time
to_date('02-20-09','mm-dd-yy') shift_end_time
, 'y' yard_departure
, to_date (20 February 09 ',' dd-mm-aa "") + effective_date level 1
of emp_exist
connect by level<=>=>
Select emp_id nvl (t1.emp_id, t2.emp_id)
nvl (t1.shift_start_time, t2.shift_start_time) shift_start_time
nvl (t1.shift_end_time, t2.shift_end_time) shift_end_time
nvl (t1.yard_departure, t2.yard_departure) yard_departure
nvl (t1.effective_date, t2.effective_date) effective_date
of emp_exist t1
join right emp_fake t2
on (t1.emp_id = t2.emp_id
and t1.effective_date = t2.effective_date)
order effective_date;
Maybe you are looking for
-
Click on Mini L9W-B-102 screen do not rotates
Hi, I bought a Satellite click on Mini L9W-B-102 yesterday with pre-installed Windows 8.1. The screen is not auto rotation in tablet mode. I can see the padlock 'Settings' screen rotation option appear and disappear when I connect and disconnect the
-
4730 proBook s: HP protect tools
How to uninstall HP ProtectTools security Manager for the upgrade of Win10 of Win7? protection tools version is 6.08.1017
-
Reference: HP Photomart C7180 all-in-One Vista operating system Error 1905 How to remove my computer HP batch files?
-
Extract values to graph 'PART 2'
This question is based of the post found here. In th attached VI, how correctly set the threshold so that all the "tips" can be displayed in the list of "epi"? I should get 3 points in the list of the PPE. Thank you hiNi
-
Office Live add-in 1.5 repeatedly offered updated
original title: Windows Update tries several times to install an update that has already succeeded. However, this update does not appear in the Add/Remove Programs list. The update is for Office Live add-in 1.5. How Windows update in order to stop tr