Help - Group By query
HelloIn the Oracle HR diagram, I want to know how many employees are there in each location. So, I wrote this query:
select employee_id, count(*) as "how many emps in this location"
from employees join departments using(department_id) join locations using (location_id)
group by location_id
but I got this error:ORA-00979: not a GROUP BY expression
How can I correct the request to give the desired result?Thank you
Hi, first of all, you need not join the departments table. Second, you must change your select clause by replacing the employee_id by location_id. Your output should be like this
location_id how many emps in this location
200 4
300 3
400 2
etc...
Published by: arizona9952 on May 16, 2013 13:23
Tags: Database
Similar Questions
-
Help: Group and query rank
Hello
By the query below, I'm looking for help on how to apply a COUNT function (based on the ""rentalno "within the RAGREEMENT table") to identify decision-making (returns the street address in the output) with most rentals. Based on the said County, I will need to rank the results so that I can only exit the rentals for the plug with most of the rentals (see the below desired output).
I'm using Oracle 11 g Express with SQL * more.
Please let me know if I need to specify further what I'm trying to achieve.
I'd appreciate any help you can provide me. Thank you!
QUERY:
the format a30 column customer;
SELECT rentalno ' RENTAL # ","RENTED"startdate, returndate «BACK»,
client.clientno | ' - ' || contact_last | ', ' ||
contact_first CLIENT, outstreet "EXIT STREET ADR."
OF ragreement
JOIN customer ON ragreement.clientno = client.clientno
JOIN vehicle ON ragreement.licenseno = vehicle.licenseno
Release of JOIN ON vehicle.outno = outlet.outno
ORDER BY rentalno;
OUTPUT CURRENT:
RENTAL # RENTED BACK CUSTOMER EXIT STREET ADR.
---------- --------- --------- ------------------------------ ------------------
3000000001 3 July 13 July 8, 13 2000000001 - Morgan, Gwen 213 rapid Run Rd
3000000002 4 July 13 2000000002 7 July 13 - Brenger, franc 213 rapid Run Rd
3000000003 5 July 13 July 7, 13 2000000003 - Pocian, Kathy 213 rapid Run Rd
3000000007 5 May 13 May 10, 13 2000000007 - McKhee, Mark 1000 bridge water
3000000008 6 May 13 May 7, 13 2000000008 - Smith, Carol 54 South N. St.
DESIRED OUTPUT:
RENTAL # RENTED BACK CUSTOMER EXIT STREET ADR.
---------- --------- --------- ------------------------------ ------------------
3000000001 3 July 13 July 8, 13 2000000001 - Morgan, Gwen 213 rapid Run Rd
3000000002 4 July 13 July 7, 13 2000000002 - Brenger, Gary 213 rapid Run Rd
3000000003 5 July 13 July 7, 13 2000000003 - Pocian, Carol 213 rapid Run Rd
SAMPLE DATA:
CREATE THE CUSTOMER TABLE
(clientNo NUMBER (10) PRIMARY KEY,)
ClientName VARCHAR2 (38),
Street VARCHAR2 (18),
City VARCHAR2 (20).
State VARCHAR2 (2),
Code postal VARCHAR2 (5).
Adresse_web VARCHAR2 (38),
Contact_first VARCHAR2 (38),
Contact_last VARCHAR2 (38),
Phone VARCHAR2 (12),
E-mail VARCHAR2 (40));
CREATE TABLE RAGREEMENT
(RentalNo NUMBER (10) PRIMARY KEY,)
StartDate DATE,
ReturnDate DATE,
MileageBefore NUMBER (10),
MileageAfter NUMBER (10),
InsuranceType VARCHAR2 (25).
ClientNo NUMBER (10),
LicenseNo VARCHAR2 (7));
CREATE TABLE VEHICLE
(LicenseNo VARCHAR2 (7) PRIMARY KEY,)
Do VARCHAR2 (12),
Model VARCHAR2 (15).
Color VARCHAR2 (15).
Year number 4.
NoDoors NUMBER (2),
Capacity NUMBER (2),
Rate number 4,
outNo NUMBER (4));
CREATE THE OUTPUT TABLE
(outNo PRIMARY KEY number 4,
outStreet VARCHAR2 (18),
outCity VARCHAR2 (20).
outState VARCHAR2 (2),
outZipCode VARCHAR2 (5).
outPhone VARCHAR2 (12),
ManagerNo NUMBER (6));
INSERT INTO CUSTOMERS VALUES ('2000000001',"University of Pittsburgh", ' 213 Fast Run Rd', 'Houston', 'PA', '68954',' www.pitt.edu', 'Gwen', 'Morgan', '7243441957',' [email protected]');
INSERT INTO CUSTOMERS VALUES ('2000000002 ', 'Free Zip','1000 Bridge Water ',' Dallas', 'WV', '23659',' www.zipfree.org', 'Frank', 'Brenger', '9856587896',' [email protected]');
INSERT INTO CUSTOMERS VALUES ('2000000003', 'GO', "Richmond', ' 54 N. South St.", "Go Go Go, Inc.", "' 97562 ', ' www.gogogo.com', 'Kathy', 'Pocian', '3048965489',' [email protected]'");
INSERT INTO CUSTOMERS VALUES ('2000000004',"Carnegie Mellon University', ' dotted 1001 Way', 'Washington', 'DC', '54865',' www.cmu.edu", "Linda", 'Betsch', '7896541235',' [email protected]');
INSERT INTO CUSTOMERS VALUES ('NSA',' 2000000005', ' Jump St. 234', 'Pittsburgh', 'PA', '21358',' www.nsa.gov', 'Vicki', 'Klein', '5986598785',' [email protected]');
INSERT INTO CUSTOMERS VALUES ('3289 Cresent Ave. ("" "" ","York","WV", '2000000006', ' FBI ', '54268', ' www.fbi.gov ', 'Brand', 'Severns', '5965897458',' [email protected]');
INSERT INTO CUSTOMERS VALUES ('2000000007 ', "Notes, Inc." ', ' 975 Sunset Blvd. ', '24973',' www.notes.org', 'Mark', 'McKhee', '7896589658', 'Canonsburg", 'PA'' [email protected]');
INSERT INTO CUSTOMERS VALUES ('2000000008', "Caterpillar, Inc.", "2045 West Pike St.', 'Cranberry', 'PA', '36597',' www.cat.com', 'Carol', 'Smith', '5426589756',' [email protected]'");
INSERT INTO CUSTOMERS VALUES ('2000000009', ' clues Kids', 72 East St. salmon ', 'Wheel', 'WV', '78564',' www.clues.com', 'Matt', 'Walker', '7896541235',' [email protected]');
INSERT INTO CUSTOMERS VALUES ('2000000010', 'Free run' ', ' Blaise 678 BC. ","Meadville","WV", '85652',' www.freelancer.org', 'Frank', 'Peer', '2135689456',' [email protected]');
INSERT INTO RAGREEMENT VALUES ('3000000001', ' 3 July 13', ' 8 July 13 ', '123000',' 123350', "LDW", '2000000001', 'BH05J9U');
INSERT INTO RAGREEMENT VALUES ('3000000002', ' 4 July 13', ' 7 July 13 ', '234567',' 234917', 'CEP', '2000000002', 'H4L0DH8');
INSERT INTO RAGREEMENT VALUES ('3000000003', ' 5 July 13', ' 7 July 13 ', ' 576858 ', '577208', 'Deleted',' 2000000003', '5HDI9TG');
INSERT INTO RAGREEMENT VALUES (' '3000000004',' 7 June 13', 11 June 13 ', '623450', ' 623800', ' CEP', '2000000004 GI0UJD7',' ');
INSERT INTO RAGREEMENT VALUES (' '3000000005',' 8 June 13', 15 June 13 ', ' 123467', 'LDW 123817', ' "', 'the GJU4Y7D', ' 2000000005');
INSERT INTO RAGREEMENT VALUES of ('3000000006', ' 4 May 13', ' 9 May 13 ', '3456', '5000', 'deleted', '2000000006',' S5BNP2S);
INSERT INTO RAGREEMENT VALUES ('3000000007',' 5 May 13', 10 May 13 ', '438', ' 788', 'deleted', '2000000007',' XCH4Y23');
INSERT INTO RAGREEMENT VALUES ('3000000008', ' 6 May 13', ' 7 May 13 ', '50', '400', 'deleted', '2000000008', 'A12F8GH');
INSERT INTO RAGREEMENT VALUES ('3000000009', ' April 2 13', ' 7 April 13 ', '45678',' 46028', "LDW", '2000000009', 'C4YUTSA');
INSERT INTO RAGREEMENT VALUES ('3000000010',' 3 April 13', 18 April 13 ', ' 7689', '8039', 'CEP', '2000000010',' 634HV2E');
INSERT IN VEHICLE VALUES ('BH05J9U', 'Ford', 'Escape', 'White', '2013', '4', '5', '120',' 1001');
INSERT INTO VEHICLE of VALUES ('H4L0DH8', 'Ford', 'Edge', 'Blue', ' 2012', '4 ', '5', '120','1001 ');
INSERT INTO VEHICLE VALUES ('5HDI9TG', 'Ford', 'Fiesta', 'Green', '2013', '4', '5',' 90 ', ' 1001');
INSERT INTO VEHICLE of VALUES ('GI0UJD7', 'Ford', 'Fusion', 'Yellow', ' 2012', '4', '5',' 90 ', ' 1002');
INSERT IN VEHICLE VALUES ('GJU4Y7D', 'Nissian","Versa", 'Teal", ' 2012', '4', '5',' 90 ', ' 1001');
INSERT INTO VALUES ('S5BNP2S', 'Nissian', 'Altima', 'Blue', '2013', '4', '5', '120','1003 ');
INSERT IN VEHICLE VALUES ('XCH4Y23', 'Nissian', 'Maxima', 'Black' ', ' 2012 ', '4 ', '5', '120',' 1002');
INSERT IN VEHICLE VALUES ('A12F8GH', 'Chevrolet', 'Cruze', 'Black', '2013', '4', '5',' 90 ', ' 1003');
INSERT IN VEHICLE VALUES ("C4YUTSA", "Chevrolet", "Malibu", 'White', ' 2012', '4 ', '5', '120',' 1004');
INSERT INTO VEHICLE VALUES ('634HV2E', 'Chevrolet', 'Impala', 'Orange', '2013', '4', '5',' 120 ', ' 1004');
INSERT INTO THE OUTPUT VALUES ("' 1001', ' 213 rapid run Rd", "Houston", "TX", '68954', '7245339865', 100009');
INSERT INTO THE OUTPUT VALUES ('1002','1000 bridge water ',' Dallas ', 'TX', ' 23659', '4125469854 ', 100008');
INSERT INTO THE OUTPUT VALUES (' 1003', ' 54 N. South St. ', 'Richmond', 'RIGHT', '97562', '7458963215', 100008');
INSERT INTO THE OUTPUT VALUES ('1004', ' 1001 pointed Way', 'Washington', 'DC', '54865', '1459632514', 100009');
INSERT INTO THE OUTPUT VALUES (' 1005', ' St. 234 Jump ', 'Pittsburgh', 'PA', '21358', '4153586452', 100010');
INSERT INTO THE OUTPUT VALUES ("1006 ', ' 3289 Cresent Ave.", "York", "AZ", '54268', '1298745635', 100010');
INSERT INTO THE OUTPUT VALUES (' ' 1007', ' 975 Sunset Blvd. ","Canonsburg', 'PA', '24973', '3698521475', 100012');
INSERT INTO THE OUTPUT VALUES ('1008', ' 2045 West Pike St.', 'Cranberry', 'CA', 36597', ' 9658745896 ', ' 100012');
INSERT INTO THE OUTPUT VALUES (' 1009', ' St. East salmon 72 ","Wheeling","WV", '78564', '2365987456', 100012');
INSERT INTO THE OUTPUT VALUES (' '1010', ' Blaise 678 BC. ","Meadville', 'OH', '85652', '1235897456', 100007');
Hello
This is called a Query Top - N. Oracle 11 (in fact, in Oracle 9.1 and upward), you can do it with the analytical functions of COUNTY and RANK, like this
WITH got_cnt AS
(
SELECT rentalno AS Location #.
startdate AS rented
, returndate, such AS returned
client.clientno | ' - '
|| contact_first
|| ', '
|| contact_last as a customer
outstreet AS outlet_street_adr
COUNT AS NTC (*) OVER (PARTITION BY outstreet)
OF ragreement
JOIN customer ON ragreement.clientno = client.clientno
JOIN vehicle ON ragreement.licenseno = vehicle.licenseno
Release of JOIN ON vehicle.outno = outlet.outno
)
got_rnk AS
(
C. SELECT
, EVALUATE () OVER (ORDER BY cnt DESC) AS rnk
OF got_cnt c
)
SELECT rental # rented, returned, customer, outlet_street_adr
OF got_rnk
WHERE rnk = 1
;
You will notice that the first auxiliary request, got_cnt, is almost what you have posted; the main difference is the column of the cnt.
Analytical functions cannot be nested, or depend on another analytic function in the same query. Since rnk depends on the cnt, they must be calculated in distinct subqueries. In addition, the analytic functions are calculated after the clause WHERE is applied. Because we want to use rnk in a WHERE clause, this means that we need an another subquery.
Thanks for posting the CREATE TABLE and INSERT statements; It is very useful.
Watch for the double quotes. To be your Publisher of this site have transformed by leaning citations, which does not recognize Oracle. Try zip code that people can use without editing.
-
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.
-
Hi gurus
need help with this query,
I want to display the records in the table emp
I want just the recordsSQL> Select Deptno,sal,sal/SUMSAL Percent,rn 2 From ( Select emp.*,Sum(Sal) Over() "SUMSAL",Row_number() Over(Order by sal Desc) rn 3 From emp 4 ) 5 / EMPNO DEPTNO SAL PERCENT RN --------- ---------- ---------- ---------- ---------- 7839 10 5000 .172265289 1 7902 20 3000 .103359173 2 7788 20 3000 .103359173 3 7566 20 2975 .102497847 4 7698 30 2850 .098191214 5 7782 10 2450 .084409991 6 7499 30 1600 .055124892 7 7844 30 1500 .051679587 8 7934 10 1300 .044788975 9 7521 30 1250 .043066322 10 7654 30 1250 .043066322 11 7876 20 1100 .037898363 12 7900 30 950 .032730405 13 7369 20 800 .027562446 14 14 rows selected.
Thank youEMPNO DEPTNO SAL PERCENT RN ---------- ---------- ---------- ---------- ---------- 7839 10 5000 .172265289 1 7902 20 3000 .103359173 2 7788 20 3000 .103359173 3 7566 20 2975 .102497847 4 7698 30 2850 .098191214 5 with sum (Percent) of remaing records..... Others .420327304
Published by: SeenuGuddu on February 27, 2011 03:39with a as ( Select Empno, Deptno ,sal, sal/SUMSAL Percent, case when rn<=5 then rn else null end rnm From (Select emp.*, Sum(Sal) Over() "SUMSAL", Row_number() Over(Order by sal Desc) rn From emp) ) select case when max(rnm) is not null then to_char(max(empno)) else 'Others:' end empno, case when max(rnm) is not null then max(deptno) else null end deptno, case when max(rnm) is not null then max(sal) else null end sal, to_char(sum(percent), '90.99') percent, max(rnm) rn from a group by rnm order by rnm
EMPNO DEPTNO SAL PERCENT RN ---------------------------------------- ---------------------- ---------------------- ------- ---------------------- 7839 10 5000 0.17 1 7902 20 3000 0.10 2 7788 20 3000 0.10 3 7566 20 2975 0.10 4 7698 30 2850 0.10 5 Others: 0.42 6 rows selected
-
Oracle Version: 11.2.0.2.0
I need assistance with the output of the query. Here is the table.
With Tbl_Nm as
(
Select 'ABC1' SYSTEM_ID, REGION 'US', 'CHI' SUB_REGION 4000 BALANCE, to_date('1-JUN-2012 10:45:00 am', 'dd-mon-yyyy hh:mi:ss am') LAST_UPD_TIME, 'A' FLAG of union double all the
Select 'PQR2', 'UK', 'LN', 2000, To_Date('1-JUL-2012 10:46:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All
Select 'ABC1', 'IND","MAMA", 3500, To_Date('1-AUG-2012 11:47:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select "LMN3", "US", "NJ", 2500, To_Date('1-SEP-2012 09:49:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select "PQR2", "UK", "MC", 2600, To_Date('1-OCT-2012 04:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select 'ABC1', 'US', 'NY', 3200, To_Date('1-OCT-2012 06:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All
Select "LMN3", "UK", "BT", 2400, To_Date('1-NOV-2012 07:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' From Dual
)
Select * from tbl_nm
I need the output below.
PQR2 UK MC 2600 1 OCTOBER 2012 04:45
ABC1 US NY 3500 October 1, 2012 06:45
LMN3 UK BT 2500 November 1, 2012 07:45
The need the disc according to this system_id flagged as "A". But if the last disc of 'd' then it must show that the amount, but the file should be displayed in 'A '.
I've tried a few and got stuck. Help, please. Not able to get a balance '.
This question is a bit similar to needing help with a query result
With Tbl_Nm as
(
Select 'ABC1' System_Id, region 'US', 'CHI' Sub_Region, 4000 balance, To_Date('1-JUN-2012 10:45:00 am', 'dd-mon-yyyy hh:mi:ss am') Last_Upd_Time, 'A' flag of double Union All
Select 'PQR2', 'UK', 'LN', 2000, To_Date('1-JUL-2012 10:46:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All
Select 'ABC1', 'IND","MAMA", 3500, To_Date('1-AUG-2012 11:47:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select "LMN3", "US", "NJ", 2500, To_Date('1-SEP-2012 09:49:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select "PQR2", "UK", "MC", 2600, To_Date('1-OCT-2012 04:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select 'ABC1', 'US', 'NY', 3200, To_Date('1-OCT-2012 06:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All
Select "LMN3", "UK", "BT", 2400, To_Date('1-NOV-2012 07:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' From Dual
)
Select System_Id, region, Sub_Region, Balance, Last_Upd_Time of Tbl_Nm T1
where t1. Last_Upd_Time = (select max (Last_Upd_Time) in the Tbl_Nm T2 where T1.) SYSTEM_ID = T2. SYSTEM_ID)
So maybe you'd then
ORDER BY DECODE(flag,'D',9,1) ASC...
to get the Ds at the end of the list.
or
ORDER BY CASE WHAT flag = has ' (your other filters) AND then 9 or 1 end CSA,...
HTH
-
Dialog box that says ' Creative Cloud Installer wants to make changes. Type your password for this purpose"- I type my password for Adobe ID (creative cloud), but it will not accept it. who should I go for help with this query?
It does not ask the cloud your computer admin password password!
-
Help with the query to select only one record from the result set in double
Hello
Please help with the query. Version of Oracle database we use is 10g R2.
I have a vision that is duplicated IDS, but they are used across the different functions. See below examples of data. Please help me with a query to select only one record (based on ID regardless of the area) from the bottom of the result set of duplicate records. For what is the point of view is there unique records, given the combination of the fields ID, Org, DF, dry, Sub-Sec
ID Org DF Sec Sub-Sec (163) CQ CPDM CPDM HD (163) PC ENG ENG ENG (163) CQ ASIC ASIC IS 8888 TS TAC TAC TAC (163) TS HE HE SW 6789 CQ INFO INFO FOS 6789 PC SECSYS SECSYS INFO1 6789 TS SECSYS SECSYS INFO2 9009 PC BMS BMS BMS1 My result set must eliminate the duplicate identifiers regardless of whoever we choose of the result set. (I mean without distinction Org, DF, s, Sub-s). My expected result set should be.
ID DSB DF SEC Sub-Sec (163) CQ CPDM CPDM HD 8888 TS TAC TAC TAC 6789 CQ INFO INFO FOS 9009 PC BMS BMS BMS1 Thank you
Orton
Hello
This sounds like a job for ROW_NUMBER:
WITH got_r_num AS
(
SELECT id, DSB, df, s, sub_sec org
ROW_NUMBER () OVER (PARTITION BY ID.
ORDER BY org
) AS r_num
OF view_x
)
SELECT id, DSB, df, sub_sec s,
OF got_r_num
WHERE r_num = 1
;
He is a Top - N query example, where you choose the elements of N (N = 1 in this case) from the top of an ordered list.
I hope that answers your question.
If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) to your sample data and the results desired from these data. (I know that you said that you were a view selection. Just for this thread, pretending it is a picture and post simple CREATE TABLE and INSERT statements to simulate your point of view).
Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places. (I didn't quite understand the explanation above. I don't know why you want toID ORG DF DRY SUB_SEC
-- --- -- --- -------
1234 CQ DPRK DPRK HD
and is not
1234 IS CQ ASIC, ASIC
or
TS 1234 IT IT SW
or
1234 CQ ASIC ASIC HD
)
If you change the query at all, post your modified version.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).See the FAQ forum: https://forums.oracle.com/message/9362002
-
Hello!
I m facing a problem with the help of oraext: query-database.
In my transformation im try the following (Simplified):
How to get the correct value when you use oraext:query - database?<xsl:template match="*"> <xsl:variable sqlQuery="select ....."/> <xsl:variable name="storeSec" select="oraext:query-database($sqlQuery,true(),true(),'jdbc/xref')/> <xsl:choose> <xsl:when test="string-length($storeSec/ROWSET/ROW[1]/STORE_PART_SECTION) > 0"> <xsl:value-of select="$storeSec/ROWSET/ROW[1]/STORE_PART_SECTION"/> </xsl:when> <xsl:otherwise> <xsl:value-of select"some other val"/> </xsl:otherwise> </xsl:choose> </xsl:template> {code} This always results in +some+ +other+ +val+ !! I´v checked the output from oraext:query-database by using getcontentAsString and if I instead test putting the expected output from oraext:queryDatabase in my variable it gives me A100 which is what i expected. {code} <xsl:template match="*"> <xsl:variable sqlQuery=select ....."/> <xsl:variable name="storeSec"> <ROWSET> <ROW num="1"> <STORE_PART_SECTION>A100</STORE_PART_SECTION> </ROW> <ROW num="2"> <STORE_PART_SECTION>XXm</STORE_PART_SECTION> </ROW> </ROWSET> </xsl:variable> <xsl:choose> <xsl:when test="string-length($storeSec/ROWSET/ROW[1]/STORE_PART_SECTION) > 0"> <xsl:value-of select="$storeSec/ROWSET/ROW[1]/STORE_PART_SECTION"/> </xsl:when> <xsl:otherwise> <xsl:value-of select"some other val"/> </xsl:otherwise> </xsl:choose> </xsl:template>
How should you exit? Several item ID with each having a value of the result set?
If Yes, then you can try following: -
need help with the query, thx
Hello
I need a little help with the query I have to write;
the table has 4 columns:
what I am asking is the following result: salary according to the latest available yearcol1 col2 col3 col4 emp_name empl_id salary year content of data: col1 col2 col3 col4 smith 12 1200 1999 smith 12 1340 2000 smith 12 1500 2001 jones 13 1550 1999 jones 13 1600 2000 aron 14 1200 2002
i.e.
ID appreciate some guidance on how to achievesmith 12 1500 2001 jones 13 1600 2000 aron 14 1200 2002
Thank you
Rgdsselect *from (select col1, col2,col3, col4,row_number() over(partition by col1 order by col4 desc) rn from
) where rn=1 -
small request I have given as below,
Month ProductNo CustomerNo units
9001 1001 Jan - 09 100
9002 1002 Jan - 09 200
9003 1003 Jan - 09 300
Jan 9001 400 ABCCustomer
9002 1004 Jan - 09 500
for all record - if column - customerNo starts with digital it must show as CN_ * other wise of the same name.
Result must be
9001 100 CN_1001-09 Jan
9002 200 CN_1002-09 Jan
9003 300 CN_1003-09 Jan
Jan 9001 400 ABCCustomer
9002 500 CN_1004-09 Jan
Can help get the queryA logic that is easier to implement this is as below
SQL> with t as (select 'jan' Month, 9001 ProductNo,'1001-09' CustomerNo,100 Units from dual union all 2 select 'jan', 9002, '1002-09', 200 from dual union all 3 select 'jan', 9003, '1003-09', 300 from dual union all 4 select 'jan', 9001, 'ABCCustomer', 400 from dual union all 5 select 'Jan', 9002, '1004-09', 500 from dual) 6 select month,productno,case when upper(substr(customerno,1,1))=lower(substr(customerno,1,1)) 7 then 'CN_'||customerno else customerno end customerno,units from t; MON PRODUCTNO CUSTOMERNO UNITS --- ---------- -------------- ---------- jan 9001 CN_1001-09 100 jan 9002 CN_1002-09 200 jan 9003 CN_1003-09 300 jan 9001 ABCCustomer 400 Jan 9002 CN_1004-09 500
TRY WITH THIS upper (substr(customerno,1,1)) = lower (substr(customerno,1,1))
-
Hi guys,.
It's me again.
Can someone help me with this query? It's a little tricky, but I can't find any solution.
Imagine I have the following table with the following data samples.
One person (its id is no id) can appear twice in my table with two different details according to his group (GID). If a user appears twice in this table, I need to retrieve the details of the first group (in this case ABC).CREATE TABLE persons ( person_id NUMBER(10), group_id VARCHAR2(10), email VARCHAR2(255), attr_1 VARCHAR2(10), attr_2 VARCHAR2(10) ); insert into persons(person_id, group_id, email, attr_1, attr_2) SELECT 1, 'ABC', '[email protected]', 'X', 'Y' FROM dual UNION ALL SELECT 1, 'DEF', '[email protected]', 'A', 'B' FROM dual UNION ALL SELECT 2, 'DEF', '[email protected]', 'A', 'B' FROM dual UNION ALL SELECT 3, 'ABC', '[email protected]', 'A', NULL FROM dual UNION ALL SELECT 3, 'DEF', '[email protected]', NULL, 'B' FROM dual UNION ALL SELECT 4, 'ABC', '[email protected]', 'X', 'Z' FROM dual UNION ALL SELECT 4, 'DEF', '[email protected]', 'E', 'B' FROM dual;
I tried with the following statement, but it is not working properly.
MIN/MAX Returns min/max per GROUP. In my case, user 4 does not have the correct values.SELECT person_id, MIN(group_id), MIN(email), MIN(attr_1), MIN(attr_2) FROM persons GROUP BY person_id; PERSON_ID MIN(GROUP_ID) MIN(EMAIL) MIN(ATTR_1) MIN(ATTR_2) ---------- ------------- ------------------------- ----------- ----------- 1 ABC [email protected] A B 2 DEF [email protected] A B 3 ABC [email protected] A B 4 ABC [email protected] E B
What I would like to have, it is something like this:
And another statement that merges the records when there are NULL values:PERSON_ID MIN(GROUP_ID) MIN(EMAIL) MIN(ATTR_1) MIN(ATTR_2) ---------- ------------- ------------------------- ----------- ----------- 1 ABC [email protected] A B 2 DEF [email protected] A B 3 ABC [email protected] A NULL -- See the null? 4 ABC [email protected] X Z -- See the X and Z
I use Oracle 10 gPERSON_ID MIN(GROUP_ID) MIN(EMAIL) MIN(ATTR_1) MIN(ATTR_2) ---------- ------------- ------------------------- ----------- ----------- 1 ABC [email protected] A B 2 DEF [email protected] A B 3 ABC [email protected] A B -- No more NULL - Value is coming from second record. 4 ABC [email protected] X Z -- See the X and Z
Any help is welcome.
Thank youAnd a sort of fusion (grabbing the next or previous value if the current is null)...
SQL> ed Wrote file afiedt.buf 1 select person_id, group_id, email, attr_1, attr_2 2 from ( 3 select person_id, group_id, email 4 ,case when attr_1 is null then 5 nvl(lead(attr_1) over (partition by person_id order by group_id), lag(attr_1) over (partition by person_id order by group_id)) 6 else attr_1 end as attr_1 7 ,case when attr_2 is null then 8 nvl(lead(attr_2) over (partition by person_id order by group_id), lag(attr_2) over (partition by person_id order by group_id)) 9 else attr_2 end as attr_2 10 ,row_number() over (partition by person_id order by group_id) as rn 11 from persons 12 ) 13* where rn = 1 SQL> / PERSON_ID GROUP_ID EMAIL ATTR_1 ATTR_2 ---------- ---------- -------------------------------------------------- ---------- ---------- 1 ABC [email protected] X Y 2 DEF [email protected] A B 3 ABC [email protected] A B 4 ABC [email protected] X Z
-
Need help with a query to group by return qroups with no result
I have the following query that checks the number of items maintenance has been done for each paragraph in a support order.
It lists all the paragraphs being checked it and the number of maintenance activities were conducted for that paragraph.
It works very well in most of the cases, except some of the facilities to break their equipment into subcatagories from a specific facility specified in the lpm.equipment_ident field.
For example, the tables and the data below are for the installation of ATL, which is breaking down for channels A and B maintenance activities
The following query illustrates 10 maintenance activities for installation ATL and the query must be 5 for ATL channel A and 5 activities for ATL channel B
This is the query, output current, output desired and all the SQL required to create the tables and data. I am using Oracle 11g
Any help would be appreciated.
-- Query SELECT req.publication_paragraph_number AS publication_paragraph -- , req.description , req.frequency , case upper (req.frequency) WHEN 'DAILY' THEN 365 WHEN 'WEEKLY' THEN 52 WHEN 'MONTHLY' THEN 12 WHEN 'QUARTERLY' THEN 4 WHEN 'SEMIANNUALLY' THEN 2 WHEN 'ANNUALLY' THEN 1 ELSE 0 END as num_req, MAX(lpm.equipment_ident) AS equipment_ident , COUNT(fsep.fac_id) as activities_performed FROM pm_requirements_table req LEFT OUTER JOIN lpm_paragraph_mapping_table pmap ON req.publication_order = pmap.publication_order AND req.publication_paragraph_number = pmap.publication_paragraph LEFT OUTER JOIN lpm ON trim(lpm.publication_paragraph) = pmap.paragraph_alias_mapping AND TRIM(lpm.publication_order) = '6310.19A' AND TRUNC(lpm.start_date, 'YEAR') = TO_DATE('01/01/2010', 'MM/DD/YYYY') AND lpm.fac_ident = 'ATL' LEFT OUTER JOIN fsep ON fsep.fac_id = lpm.fac_ident AND fsep.facility = lpm.fac_type GROUP BY req.publication_paragraph_number, req.description, req.frequency ORDER BY req.publication_paragraph_number;
-- Current Output "PUBLICATION_PARAGRAPH" "FREQUENCY" "NUM_REQ" "EQUIPMENT_IDENT" "ACTIVITIES_PERFORMED" "161A" "WEEKLY" "52" "CHAN B" "10" "161B" "WEEKLY" "52" "CHAN B" "10" "161C" "WEEKLY" "52" "CHAN B" "10" "161D(1)" "WEEKLY" "52" "" "0" "161D(2)" "WEEKLY" "52" "" "0" "161D(3)" "WEEKLY" "52" "" "0" "161D(4)" "WEEKLY" "52" "" "0" "161D(5)" "WEEKLY" "52" "" "0" "161D(6)" "WEEKLY" "52" "" "0" "161E" "WEEKLY" "52" "" "0" "161F" "WEEKLY" "52" "" "0" "161G" "WEEKLY" "52" "" "0" "161H" "WEEKLY" "52" "" "0" "161I" "WEEKLY" "52" "" "0" "161J" "WEEKLY" "52" "" "0" "161K" "WEEKLY" "52" "" "0"
-- Desired Output "PUBLICATION_PARAGRAPH" "FREQUENCY" "NUM_REQ" "EQUIPMENT_IDENT" "ACTIVITIES_PERFORMED" "161A" "WEEKLY" "52" "CHAN A" "5" "161A" "WEEKLY" "52" "CHAN B" "5" "161B" "WEEKLY" "52" "CHAN A" "5" "161B" "WEEKLY" "52" "CHAN B" "5" "161C" "WEEKLY" "52" "CHAN A" "5" "161C" "WEEKLY" "52" "CHAN B" "5" "161D(1)" "WEEKLY" "52" "" "0" "161D(2)" "WEEKLY" "52" "" "0" "161D(3)" "WEEKLY" "52" "" "0" "161D(4)" "WEEKLY" "52" "" "0" "161D(5)" "WEEKLY" "52" "" "0" "161D(6)" "WEEKLY" "52" "" "0" "161E" "WEEKLY" "52" "" "0" "161F" "WEEKLY" "52" "" "0" "161G" "WEEKLY" "52" "" "0" "161H" "WEEKLY" "52" "" "0" "161I" "WEEKLY" "52" "" "0" "161J" "WEEKLY" "52" "" "0" "161K" "WEEKLY" "52" "" "0"
Published by: George Heller on July 20, 2011 13:45-- Tables and Data CREATE TABLE "LPM" ( "LOG_ID" NUMBER(22,0) NOT NULL ENABLE, "FAC_IDENT" VARCHAR2(5 BYTE), "FAC_TYPE" VARCHAR2(5 BYTE), "CODE_CATEGORY" NUMBER(22,0) NOT NULL ENABLE, "SUPPLEMENTAL_CODE" VARCHAR2(1 BYTE), "MAINT_ACTION_CODE" VARCHAR2(1 BYTE), "INTERRUPT_CONDITION" VARCHAR2(22 BYTE), "ATOW_CODE" VARCHAR2(22 BYTE), "SECTOR_CODE" VARCHAR2(5 BYTE), "LOG_STATUS" VARCHAR2(3 BYTE) NOT NULL ENABLE, "START_DATE" DATE, "START_DATETIME" VARCHAR2(22 BYTE), "END_DATE" DATE, "END_DATETIME" VARCHAR2(22 BYTE), "MODIFIED_DATETIME" VARCHAR2(22 BYTE), "WR_AREA" VARCHAR2(6 BYTE), "SHORT_NAME" VARCHAR2(15 BYTE), "EQUIPMENT_IDENT" VARCHAR2(15 BYTE), "INTERVAL_CODE" VARCHAR2(255 BYTE), "EARLIEST_DATE" VARCHAR2(4000 BYTE), "EARLIEST_DATETIME" VARCHAR2(255 BYTE), "SCHEDULED_DATE" DATE, "SCHEDULED_DATETIME" VARCHAR2(22 BYTE), "LATEST_DATE" DATE, "LATEST_DATETIME" VARCHAR2(22 BYTE), "WR_CREW_UNIT" VARCHAR2(10 BYTE), "WR_WATCH" VARCHAR2(1 BYTE), "PUBLICATION_ORDER" VARCHAR2(30 BYTE), "PUBLICATION_ORDER_ORIGINAL" VARCHAR2(30 BYTE), "PUBLICATION_PARAGRAPH" VARCHAR2(30 BYTE), "PUBLICATION_PARAGRAPH_ORIGINAL" VARCHAR2(30 BYTE), "NUMBER_OF_TASKS" VARCHAR2(25 BYTE), "LOG_SUMMARY" VARCHAR2(255 BYTE), "COMMENTS" CLOB, "RELATED_LOGS" CLOB, "LPMANTAC_ID" NUMBER ); CREATE TABLE "FSEP" ( "FAC_ID" VARCHAR2(10 BYTE), "FACILITY" VARCHAR2(5 BYTE), "FAC_LOCATION" VARCHAR2(13 BYTE), "FAC_STATE" VARCHAR2(2 BYTE), "REGION" VARCHAR2(2 BYTE), "COST_CENTER" VARCHAR2(8 BYTE) NOT NULL ENABLE, "ATOW_ORG" VARCHAR2(150 BYTE), "ATOW_ORG_DESCRIPTION" VARCHAR2(150 BYTE), "SVC_AREA" VARCHAR2(5 BYTE), "SECTOR_CODE" VARCHAR2(5 BYTE), "FAC_CODE" VARCHAR2(20 BYTE), "FAC_STATUS" CHAR(1 BYTE) NOT NULL ENABLE, "RESTORATION_CODE" VARCHAR2(2 BYTE), "RESPONSIBILITY_CODE" CHAR(1 BYTE), "POWER_CODE" CHAR(1 BYTE), "FAC_STATUS_DATE" DATE, "FAC_SWAP_DATE" DATE, "CHANGE_DATE" VARCHAR2(22 BYTE), "GSA_ADDRESS" VARCHAR2(15 BYTE), "INV" VARCHAR2(2 BYTE), "SDP_TYPE" VARCHAR2(5 BYTE), "SDP_IDENT" VARCHAR2(4 BYTE), "CONTROL_IDENT" VARCHAR2(10 BYTE), "REMOTE_IDENT" VARCHAR2(10 BYTE), "MONITOR_IDENT" VARCHAR2(4 BYTE), "RUNWAY" VARCHAR2(3 BYTE), "ASSOC_AIRPORT" VARCHAR2(4 BYTE), "FAC_MPS_SITE" CHAR(4 BYTE), "FREQS_IN_PLACE" NUMBER(22,0), "CONGRESSIONAL_DIS" VARCHAR2(2 BYTE), "CONTRACT_MAINT_PER" NUMBER(22,0), "AIR_COND" CHAR(1 BYTE), "FAC_UNITS" NUMBER(22,0), "ET_PRIMARY_IDENT" VARCHAR2(4 BYTE), "ET_PRIMARY_TYPE" VARCHAR2(5 BYTE), "ENV_PRIMARY_IDENT" VARCHAR2(4 BYTE), "ENV_PRIMARY_TYPE" VARCHAR2(5 BYTE), "FAC_CODE_DESC" VARCHAR2(100 BYTE), "STATUS_DESC" VARCHAR2(50 BYTE), "RESTORATION_DESC" VARCHAR2(32 BYTE), "POWER_DESC" VARCHAR2(500 BYTE), "LATITUDE" VARCHAR2(150 BYTE), "LONGITUDE" VARCHAR2(150 BYTE), "ELEVATION" VARCHAR2(22 BYTE), "MOD_COUNT" VARCHAR2(22 BYTE), "HYPERLINK" VARCHAR2(255 BYTE), "FSEPANTAC_ID" NUMBER ); CREATE TABLE "LPM_PARAGRAPH_MAPPING_TABLE" ( "PUBLICATION_ORDER" VARCHAR2(30 BYTE), "PUBLICATION_PARAGRAPH" VARCHAR2(30 BYTE), "PARAGRAPH_ALIAS_MAPPING" VARCHAR2(30 BYTE), "LPMTANTAC_ID" NUMBER ); CREATE TABLE "PM_REQUIREMENTS_TABLE" ( "PUBLICATION_ORDER" VARCHAR2(30 BYTE), "PUBLICATION_PARAGRAPH_NUMBER" VARCHAR2(30 BYTE), "DESCRIPTION" VARCHAR2(4000 BYTE), "FREQUENCY" VARCHAR2(30 BYTE), "CHECK_OR_MAINTENANCE" VARCHAR2(22 BYTE), "PRTANTAC_ID" NUMBER); Insert into lpm (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,COMMENTS,RELATED_LOGS,LPMANTAC_ID) values (108306002,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('02-MAY-10','DD-MON-RR'),'05/02/2010 21:00',to_date('02-MAY-10','DD-MON-RR'),'05/02/2010 21:30','05/03/2010 1:07','RADAR','SYS','CHAN B','W','05/02/2010','05/02/2010 0:00',to_date('05-MAY-10','DD-MON-RR'),'05/05/2010 0:00',to_date('08-MAY-10','DD-MON-RR'),'05/08/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null, EMPTY_CLOB(), EMPTY_CLOB(),14297); Insert into lpm (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,COMMENTS,RELATED_LOGS,LPMANTAC_ID) values (108306102,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('02-MAY-10','DD-MON-RR'),'05/02/2010 21:00',to_date('02-MAY-10','DD-MON-RR'),'05/02/2010 21:30','05/03/2010 1:07','RADAR','SYS','CHAN A','W','05/02/2010','05/02/2010 0:00',to_date('05-MAY-10','DD-MON-RR'),'05/05/2010 0:00',to_date('08-MAY-10','DD-MON-RR'),'05/08/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null, EMPTY_CLOB(), EMPTY_CLOB(),14298); Insert into lpm (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,COMMENTS,RELATED_LOGS,LPMANTAC_ID) values (104188402,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('26-APR-10','DD-MON-RR'),'4/26/2010 13:33',to_date('26-APR-10','DD-MON-RR'),'4/26/2010 13:46','4/26/2010 15:23','RADAR','SYS','CHAN A','W','4/25/2010','4/25/2010 0:00',to_date('28-APR-10','DD-MON-RR'),'4/28/2010 0:00',to_date('01-MAY-10','DD-MON-RR'),'05/01/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null, EMPTY_CLOB(), EMPTY_CLOB(),14306); Insert into lpm (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,COMMENTS,RELATED_LOGS,LPMANTAC_ID) values (104188502,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('26-APR-10','DD-MON-RR'),'4/26/2010 13:33',to_date('26-APR-10','DD-MON-RR'),'4/26/2010 13:46','4/26/2010 15:23','RADAR','SYS','CHAN B','W','4/25/2010','4/25/2010 0:00',to_date('28-APR-10','DD-MON-RR'),'4/28/2010 0:00',to_date('01-MAY-10','DD-MON-RR'),'05/01/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null, EMPTY_CLOB(), EMPTY_CLOB(),14307); Insert into lpm (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,COMMENTS,RELATED_LOGS,LPMANTAC_ID) values (101223702,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('19-APR-10','DD-MON-RR'),'4/19/2010 1:30',to_date('19-APR-10','DD-MON-RR'),'4/19/2010 2:10','4/19/2010 3:12','RADAR','SYS','CHAN B','W','4/18/2010','4/18/2010 0:00',to_date('21-APR-10','DD-MON-RR'),'4/21/2010 0:00',to_date('24-APR-10','DD-MON-RR'),'4/24/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null, EMPTY_CLOB(), EMPTY_CLOB(),14322); Insert into lpm (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,COMMENTS,RELATED_LOGS,LPMANTAC_ID) values (101223802,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('19-APR-10','DD-MON-RR'),'4/19/2010 1:30',to_date('19-APR-10','DD-MON-RR'),'4/19/2010 2:10','4/19/2010 3:12','RADAR','SYS','CHAN A','W','4/18/2010','4/18/2010 0:00',to_date('21-APR-10','DD-MON-RR'),'4/21/2010 0:00',to_date('24-APR-10','DD-MON-RR'),'4/24/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null, EMPTY_CLOB(), EMPTY_CLOB(),14323); Insert into lpm (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,COMMENTS,RELATED_LOGS,LPMANTAC_ID) values (96642402,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('11-APR-10','DD-MON-RR'),'04/11/2010 11:10',to_date('11-APR-10','DD-MON-RR'),'04/11/2010 11:15','04/11/2010 12:51','RADAR','SYS','CHAN B','W','04/11/2010','04/11/2010 0:00',to_date('14-APR-10','DD-MON-RR'),'4/14/2010 0:00',to_date('17-APR-10','DD-MON-RR'),'4/17/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null, EMPTY_CLOB(), EMPTY_CLOB(),14335); Insert into lpm (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,COMMENTS,RELATED_LOGS,LPMANTAC_ID) values (96642302,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('11-APR-10','DD-MON-RR'),'04/11/2010 11:05',to_date('11-APR-10','DD-MON-RR'),'04/11/2010 11:10','04/11/2010 12:51','RADAR','SYS','CHAN A','W','04/11/2010','04/11/2010 0:00',to_date('14-APR-10','DD-MON-RR'),'4/14/2010 0:00',to_date('17-APR-10','DD-MON-RR'),'4/17/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null, EMPTY_CLOB(), EMPTY_CLOB(),14336); Insert into lpm (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,COMMENTS,RELATED_LOGS,LPMANTAC_ID) values (92805502,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 18:10',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 18:22','04/07/2010 19:04','RADAR','SYS','CHAN A','W','04/04/2010','04/04/2010 0:00',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 0:00',to_date('10-APR-10','DD-MON-RR'),'04/10/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null, EMPTY_CLOB(), EMPTY_CLOB(),14342); Insert into lpm (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,COMMENTS,RELATED_LOGS,LPMANTAC_ID) values (92805402,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 17:53',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 18:05','04/07/2010 19:04','RADAR','SYS','CHAN B','W','04/04/2010','04/04/2010 0:00',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 0:00',to_date('10-APR-10','DD-MON-RR'),'04/10/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null, EMPTY_CLOB(), EMPTY_CLOB(),14343); Insert into fsep (FAC_ID,FACILITY,FAC_LOCATION,FAC_STATE,REGION,COST_CENTER,ATOW_ORG,ATOW_ORG_DESCRIPTION,SVC_AREA,SECTOR_CODE,FAC_CODE,FAC_STATUS,RESTORATION_CODE,RESPONSIBILITY_CODE,POWER_CODE,FAC_STATUS_DATE,FAC_SWAP_DATE,CHANGE_DATE,GSA_ADDRESS,INV,SDP_TYPE,SDP_IDENT,CONTROL_IDENT,REMOTE_IDENT,MONITOR_IDENT,RUNWAY,ASSOC_AIRPORT,FAC_MPS_SITE,FREQS_IN_PLACE,CONGRESSIONAL_DIS,CONTRACT_MAINT_PER,AIR_COND,FAC_UNITS,ET_PRIMARY_IDENT,ET_PRIMARY_TYPE,ENV_PRIMARY_IDENT,ENV_PRIMARY_TYPE,FAC_CODE_DESC,STATUS_DESC,RESTORATION_DESC,POWER_DESC,LATITUDE,LONGITUDE,ELEVATION,MOD_COUNT,HYPERLINK,FSEPANTAC_ID) values ('ATL','ASR','ATLANTA','GA','SO','081LB','WEQ1C','Hartsfield Radar SSC','ESA','SO1LB','453ACA','D','4','A','A',to_date('01-OCT-50','DD-MON-RR'),to_date('01-OCT-95','DD-MON-RR'),'11/17/2010 8:51','43JW','RD','TRACO','A80','A80','ATL','A80',null,'ATL','ZTL ',0,'5',0,'A',1,null,null,null,null,'ASR-9 STANDARD FACILITY','Commissioned/Full Service','Up to 4 Hours','Denotes a commercial power source a standby engine generator and an Uninterruptible Power Supply (UPS). This configuration shall provide uninterruptible conditioned power with AC voltage in and AC voltage out.','33.62875','-8.43003','1030','2','http://technet.faa.gov/fsep/fsepDetail.asp?recordno=ASRATL',32084); Insert into fsep (FAC_ID,FACILITY,FAC_LOCATION,FAC_STATE,REGION,COST_CENTER,ATOW_ORG,ATOW_ORG_DESCRIPTION,SVC_AREA,SECTOR_CODE,FAC_CODE,FAC_STATUS,RESTORATION_CODE,RESPONSIBILITY_CODE,POWER_CODE,FAC_STATUS_DATE,FAC_SWAP_DATE,CHANGE_DATE,GSA_ADDRESS,INV,SDP_TYPE,SDP_IDENT,CONTROL_IDENT,REMOTE_IDENT,MONITOR_IDENT,RUNWAY,ASSOC_AIRPORT,FAC_MPS_SITE,FREQS_IN_PLACE,CONGRESSIONAL_DIS,CONTRACT_MAINT_PER,AIR_COND,FAC_UNITS,ET_PRIMARY_IDENT,ET_PRIMARY_TYPE,ENV_PRIMARY_IDENT,ENV_PRIMARY_TYPE,FAC_CODE_DESC,STATUS_DESC,RESTORATION_DESC,POWER_DESC,LATITUDE,LONGITUDE,ELEVATION,MOD_COUNT,HYPERLINK,FSEPANTAC_ID) values ('ATL','GS','ATLANTA','GA','SO','081MB','WEQ1A','Hartsfield Nav/Comm SSC','ESA','SO1MB','314JAH','D','24','A','D',to_date('18-NOV-49','DD-MON-RR'),to_date('01-DEC-96','DD-MON-RR'),'3/4/2009 14:40','43JX','21','ATCT','ATL','ATL',null,'A80','08R','ATL','ZTL ',0,'5',0,'A',1,null,null,null,null,'MARK 20 CAPTURE EFFECT CAT III W/RMM','Commissioned/Full Service','Up to 24 Hours','Denotes a commercial power source and a battery standby power system. A UPS is not included in this category.','33.64788','-84.43426','1012','2','http://technet.faa.gov/fsep/fsepDetail.asp?recordno=GSATL',32109); Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161A','161',1708); Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161A','161A-J',1709); Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161B','161',1736); Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161B','161A-J',1737); Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161C','161',1765); Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161C','161A-J',1766); Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161C','161(A-->K)',1769); Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161C','161(A-K)',1774); Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161C','161.(A-C).',1775); Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161D(1)','161',1793); Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161D(1)','161161 A-J',1794); Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161D(2)','161',1821); Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161D(2)','161 A-J',1822); Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161D(2)','161(A-->K)',1825); Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161K','161.K',1825); Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161A','Check transmitter average rf power output','WEEKLY',null,3); Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161B','Check transmitter VSWR','WEEKLY',null,4); Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161C','Check RMS transmitter pulse width','WEEKLY',null,5); Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161D(1)','Check filament current','WEEKLY',null,6); Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161D(2)','Check focus coil current','WEEKLY',null,7); Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161D(3)','Check Klystron voltage','WEEKLY',null,8); Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161D(4)','Check Klystron current','WEEKLY',null,9); Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161D(5)','Check PFN voltage','WEEKLY',null,10); Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161D(6)','Check vacuum pump current','WEEKLY',null,11); Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161E','Check target receiver MDS','WEEKLY',null,12); Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161F','Check target receiver NF','WEEKLY',null,13); Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161G','Check target receiver recovery','WEEKLY',null,14); Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161H','Check weather receiver MDS','WEEKLY',null,15); Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161I','Check weather receiver NF','WEEKLY',null,16); Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161J','Check weather receiver recovery','WEEKLY',null,17); Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161K','Check spare modem operation','WEEKLY',null,18);
Published by: George Heller on July 20, 2011 13:46
Published by: George Heller on July 20, 2011 13:48Hi, George.
I think I understand now!
You want outer join table req on the result of all the other joined tables. You want all the lines of the req to be represented in the result set, even if they have no match in the other tables, but it is the only outer join you want. You don't want to necessarily, for example, all rows in the table pmap represented. In this case, the join involving req should be an outer join, but all the other joins are inner joins.Here's a way to do it:
SELECT req.publication_paragraph_number AS publication_paragraph -- , req.description , req.frequency , CASE UPPER (req.frequency) WHEN 'DAILY' THEN 365 WHEN 'WEEKLY' THEN 52 WHEN 'MONTHLY' THEN 12 WHEN 'QUARTERLY' THEN 4 WHEN 'SEMIANNUALLY' THEN 2 WHEN 'ANNUALLY' THEN 1 ELSE 0 END AS num_req , lpm.equipment_ident , COUNT (fsep.fac_id) AS activities_performed FROM pm_requirements_table req LEFT OUTER JOIN ( lpm_paragraph_mapping_table pmap JOIN lpm ON TRIM (lpm.publication_paragraph) = pmap.paragraph_alias_mapping AND TRIM (lpm.publication_order) = '6310.19A' AND TRUNC (lpm.start_date, 'YEAR') = TO_DATE ('01/01/2010', 'MM/DD/YYYY') AND lpm.fac_ident = 'ATL' JOIN fsep ON fsep.fac_id = lpm.fac_ident AND fsep.facility = lpm.fac_type ) ON req.publication_order = pmap.publication_order AND req.publication_paragraph_number = pmap.publication_paragraph GROUP BY req.publication_paragraph_number, req.description, req.frequency, lpm.equipment_ident ORDER BY req.publication_paragraph_number ;
Only the FROM clause has changed since yesterday.
Output:` ACTIV PUBLICAT ITIES ION_PARA EQUIPMEN _PERF GRAPH FREQUENCY NUM_REQ T_IDENT ORMED -------- --------- ---------- -------- ----- 161A WEEKLY 52 CHAN A 5 161A WEEKLY 52 CHAN B 5 161B WEEKLY 52 CHAN A 5 161B WEEKLY 52 CHAN B 5 161C WEEKLY 52 CHAN A 5 161C WEEKLY 52 CHAN B 5 161D(1) WEEKLY 52 0 161D(2) WEEKLY 52 0 161D(3) WEEKLY 52 0 161D(4) WEEKLY 52 0 161D(5) WEEKLY 52 0 161D(6) WEEKLY 52 0 161E WEEKLY 52 0 161F WEEKLY 52 0 161G WEEKLY 52 0 161H WEEKLY 52 0 161I WEEKLY 52 0 161J WEEKLY 52 0 161K WEEKLY 52 0
-
Help with the query to return the results of the group in the table?
Hello
Im a total noob, so please be nice...!
I'm looking around a table contains a column of WORD and a WORD_TYPE_ID column.
Words can have the same type_id.
What I'm trying to do is to write a query that will return the longest word for each word_type_id.
I tried for hours to get it and everything seems to get is two error messages or just the longest word in the whole WORD column.
Is the furthest I can get before things break down...
Select Word
table
where
Length (Word) =
(
Select
Max (length (Word))
table
)
Any help on this or if I could be pointed in the right direction it would be greatly appreciated.
Thank youHello
Welcome to the forum!
Here's one way:
SELECT word_type_id , MIN (word) KEEP (DENSE_RANK LAST ORDDER BY LENGTH (word)) AS longest_word FROM table_x GROUP BY word_type_id;
If there be a tie in some word_type_id (i.e. 2 or more words have exactly the same length, which is the longest in this group) the expression above will return the first one alphabetically. (This is what means here MIN.)
Published by: Frank Kulash, 11 August 2009 13:56
You almost had it.
As you have noticed, you get the longest line across the table. This is because your subquery was watching the entire table.
If you to correlate the subquery to the row in the main table, as shown below, you can get the longest word in each group:select word from table m -- m for main where length (word) = ( select max (length(word)) from table where word_type_id = m.word_type_id -- New );
-
Ask for help with the query group by
Hello
I have the following table with values structure
I have the following requirement, the output should be:CREATE TABLE DUMMY ( SR_NUMBER VARCHAR2(100 CHAR), ASSIGNMENT_GROUP VARCHAR2(100 CHAR), REASSIGNMENT_COUNT VARCHAR2(100 CHAR), CREATED DATE, CLOSED DATE, TARGET_DATE DATE ) insert into dummy values('AAA','A','1','02-OCT-11','25-OCT-11','09-OCT-11'); insert into dummy values('ABC','A','1','03-SEP-12','26-SEP-11','10-SEP-11'); insert into dummy values('AVB','A','1','02-NOV-13','25-NOV-13','09-NOV-13'); insert into dummy values('AFT','B','1','02-OCT-11','25-OCT-11','09-OCT-11'); insert into dummy values('ACS','B','1','02-JAN-12','25-JAN-12','09-JAN-12'); insert into dummy values('AVC','B','1','02-OCT-13','25-OCT-13','09-OCT-13'); insert into dummy values('AAD','B','1','02-MAR-14','25-MAR-14','09-MAR-14'); insert into dummy values('AAA','C','1','02-OCT-11','25-OCT-11','09-OCT-11'); insert into dummy values('AAA','D','1','02-JUN-11','25-JUN-11','09-JUN-11'); insert into dummy values('AAA','E','1','02-APR-12','25-APR-12','09-APR-12'); insert into dummy values('AAA','A','1','02-FEB-13','25-FEB-13','09-FEB-13'); ?
Number of ticket (sr_number)
% of tickets inside the DL
Number of tickets inside the DL
Average cycle time (cycle time = closing date - date of creation)
Total cycle time (cycle time = closing date - date of creation)
Number of reallocations (sum)
DL - (deadline) formula is, closed date < = target_date
This should be displayed, grouped by year, then month, then the assignment group. The values must be in descending order (dates) is not sure that group in operation here.
I am able to write the code base of the foregoing, but group from the year, month, and group assignment is pretty confusing to me.
Can someone give me a voucher code...This may not give you exactly what you want, but if all goes well, it will give you something to work with:
WITH tickets AS ( SELECT TO_CHAR(created, 'YYYY') created_year, TO_CHAR(created, 'MM') created_month, assignment_group, COUNT(sr_number) ticket_count, AVG(closed - created) avg_cycle_time, SUM(closed - created) tot_cycle_time, COUNT(reassignment_count) reassign_count FROM dummy GROUP BY TO_CHAR(created, 'YYYY'), TO_CHAR(created, 'MM'), assignment_group ), dl_tickets AS ( SELECT TO_CHAR(created, 'YYYY') created_year, TO_CHAR(created, 'MM') created_month, assignment_group, COUNT(sr_number) ticket_in_dl_count FROM dummy WHERE closed <= target_date GROUP BY TO_CHAR(created, 'YYYY'), TO_CHAR(created, 'MM'), assignment_group ) SELECT t.created_year, t.created_month, t.assignment_group, t.ticket_count, NVL(dl.ticket_in_dl_count, 0) ticket_in_dl_count, NVL(dl.ticket_in_dl_count/t.ticket_count, 0) * 100 pct_ticket_in_dl_count, t.avg_cycle_time, t.tot_cycle_time, t.reassign_count FROM tickets t, dl_tickets dl WHERE t.created_year = dl.created_year (+) AND t.created_month = dl.created_month (+) ORDER BY created_year DESC, created_month DESC
Published by: user1983440 on May 27, 2013 15:47 - added reassign_count
Published by: user1983440 on May 27, 2013 15:54 - added ORDER BY
-
Help with the query GROUP BY?
Why the habit of this work? When I run the code with the first where clause it works fine.
It returns the result that there is a diffirating marked "A".select diffrating, count (diffrating) from IT220_HOLIDAYDETAILS where diffrating = 'A' GROUP BY diffrating
However, when I try to add other clauses he says "no data found"?
How can this be when he came 'A' data in the first place? Surely, it should return 'A' as a negative because it worked before?select diffrating, count (diffrating) from IT220_HOLIDAYDETAILS where diffrating = 'A' and diffrating = 'B' and diffrating = 'C' and diffrating = 'D' and diffrating = 'E' GROUP BY diffrating
What I want is to count all results for each diffrating and return them. Any reason, why it does not work?
Thanks in advance!It returns nothing because you try to select a diffrating whose value has, b, c, d and e at the same time.
select diffrating, count (diffrating) from IT220_HOLIDAYDETAILS GROUP BY diffrating
is not already display what you want?
Maybe you are looking for
-
My i-cloud email account is closed because I did not use to iTuenes.
I got the Apple e-mail <[email protected]> with subject ""unlock now until you lose it "." I often use i-Cloud email. But because I have not bought anything on the same iTunes account, that apple is forced to close my account. Is it true. I
-
Color Laserjet 1600 Printer driver for Mac OS x 10.7
I need a driver for a Mac OSX10.7 laserjet 1600 color someone knows if it is available?
-
BlackBerry Smartphones files restore my backup
I recently sent my 9500 away for repair and as advised saved pictures, contacts, etc. using the Desktop Manager. I come back today the BB but cannot return data to the phone. It is stored as a file IPD, which I can't open, and I'm at a loss on how
-
Where can I find the Windows Live Mail program only. NOT 'Live Essentials '.
Using Win 7 Pro. Have been throughout the MSN site and it keeps you govern to Win Live Ess. Windows has a "tracking cookie" that I want to get rid of too.
-
AdobeAcrobat Reader 11 Installation without Service Updater?
Hello!Is it possible to install Adobe Acrobat Reader 11 without install "Adobe Acrobat Update Service"?Is it possible to exclude the Setup program for the service? Is there a setting or something else to install the drive without having to install th