Need help with a query MySQL =)
The following query displays the arguments in the order of how many times that each bid was seen by a visitor in the last 7 days, from the highest to the lowest. How can I show him each record in the table 'submission_data', even if there is no matching record in the table 'submission_views '? Basically I want the presentations with a 'id_count' of 0 to display at the end.SELECT COUNT (Distinct submission_views.submission_id, submission_views.ip_address) AS id_count, submission_data.id, submission_data.thumbnail_source, submission_data.title, submission_data.type
FROM submission_data LEFT JOIN submission_views ON submission_views.submission_id = submission_data.id
WHERE submission_views.timestamp > DATE_SUB (NOW (), INTERVAL of 7 DAYS)
GROUP BY submission_data.id
ORDER BY id_count DESC
> WHERE (submission_views.timestamp > DATE_SUB (NOW (), INTERVAL of 7 DAYS))
(> OR submission_views.timestamp = NULL)
Use the IS NULL, not the = operator.
Tags: Dreamweaver
Similar Questions
-
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
-
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 -
Need help with the query. Help, please
Hey everyone, need your help. Thank you in advance. In my view, there is function Pivot. Just do not know how to use this function. I have the query that works. The result is:
11-111-1111 Vlad 16505 01/04/2013 5 August 13 dental plan pre-tax amount 29,65
11-111-1111 Vlad 16505 01/04/2013 dental pre-tax 5 August 13 Plan level EE + SP
11-111-1111 16505 Vlad 01/04/2013 5 August 13 pre-tax Option TOP dental plan
11-111-1111 Vlad 16505 01/04/2013 5 August 13 pre-tax dental care plan pay the value
11-111-1111 16505 Vlad 01/04/2013 dental pre-tax 5 August 13 Plan period Type
11-111-1111 Vlad 16505 01/04/2013 amount pre-tax medical Plan of 5 August 13 149
11-111-1111 Vlad 16505 01/04/2013 5 August 13 pre-tax Medical Plan level EE + SP
11-111-1111 Vlad 16505 01/04/2013 5 August 13 pre-tax Plan medical Option MED
11-111-1111 Vlad 16505 01/04/2013 5 August 13 plan pre-tax pay value
11-111-1111 16505 Vlad 01/04/2013 5 August 13 pre-tax Medical Plan period Type
11-111-1111 Vlad 16505 01/04/2013 5 August 13 pre-tax Plan PPO medical Plan
11-111-1111 Vlad 16505 01/04/2013 5 August 13 Vision Plan amount 5.94 pre-tax
But I need the result to be
Amount of SSN ID name item level Option PayValue period Type
11-111-1111 Vlad 16505 01/04/2013 null null high of 5 August 13 pre-tax Dental Plan 29,65 EE + SP
11-111-1111 Vlad 16505 01/04/2013 null null MED 5 August 13 149 medical plan pre-tax EE + SP
11-111-1111 Vlad 16505 01/04/2013 Vision Plan before taxes of 5 August 13
Select distinct
' 11-111-1111 "as ssn,
WOMEN'S WEAR. Employee_number,
"Vlad" as EMPLOYEE_FULL_NAME,
TO_CHAR (papf.start_date, "MM/DD/YYYY") as Date_Of_Hire
a.effective_start_date,
PETF.element_name,
pivf. Name,
peevf.screen_entry_valueOf
PER_all_PEOPLE_F women's wear
per_assignments_f A
pay_element_types_f petf
pay_element_links_f pelf
PAY_ELEMENT_ENTRIES_F penf
PAY_ELEMENT_ENTRY_VALUES_F peevf
pay_input_values_f pivf
WHERE
PETF.element_name ('Dental Plan before taxes', 'Medical Plan before taxes', "Vision Plan before taxes")
and petf. ELEMENT_TYPE_ID = pelf. ELEMENT_TYPE_ID
and (trunc (sysdate) BETWEEN pelf. EFFECTIVE_START_DATE AND pelf. EFFECTIVE_END_DATE)
and (pelf. ELEMENT_LINK_ID = penf. ELEMENT_LINK_ID and a.assignment_id = penf. ASSIGNMENT_ID)
and (trunc (sysdate) BETWEEN penf. EFFECTIVE_START_DATE AND penf. EFFECTIVE_END_DATE)
and penf. ELEMENT_ENTRY_ID = peevf. ELEMENT_ENTRY_ID
and peevf. INPUT_VALUE_ID = pivf. INPUT_VALUE_ID
AND papf.employee_number IS NOT NULL
AND A.assignment_type = 'E '.
AND A.person_id = papf.person_id
and papf.effective_end_date > sysdate
and a.effective_end_date > sysdate
and (trunc (sysdate) BETWEEN women's wear. EFFECTIVE_START_DATE AND women's wear. EFFECTIVE_END_DATE)
and a.effective_start_date = (select MAX (effective_start_date) from PER_ASSIGNMENTS_f where assignment_id = a.assignment_id)
and a.assignment_id = 42643
and a.assignment_status_type_id = '1'
order of petf.element_name;Change with your query
SELECT * FROM (select distinct)
' 11-111-1111 "as ssn,
WOMEN'S WEAR. Employee_number,
"Vlad" as employee_full_name,
TO_CHAR (papf.start_date, "MM/DD/YYYY") as date_of_hire
a.effective_start_date,
PETF.element_name,
pivf. Name,
peevf.screen_entry_value
Of
PER_all_PEOPLE_F women's wear
per_assignments_f A
pay_element_types_f petf
pay_element_links_f pelf
PAY_ELEMENT_ENTRIES_F penf
PAY_ELEMENT_ENTRY_VALUES_F peevf
pay_input_values_f pivf
WHERE
PETF.element_name ('Dental Plan before taxes', 'Medical Plan before taxes', "Vision Plan before taxes")
and petf. ELEMENT_TYPE_ID = pelf. ELEMENT_TYPE_ID
and (trunc (sysdate) BETWEEN pelf. EFFECTIVE_START_DATE AND pelf. EFFECTIVE_END_DATE)
and (pelf. ELEMENT_LINK_ID = penf. ELEMENT_LINK_ID and a.assignment_id = penf. ASSIGNMENT_ID)
and (trunc (sysdate) BETWEEN penf. EFFECTIVE_START_DATE AND penf. EFFECTIVE_END_DATE)
and penf. ELEMENT_ENTRY_ID = peevf. ELEMENT_ENTRY_ID
and peevf. INPUT_VALUE_ID = pivf. INPUT_VALUE_ID
AND papf.employee_number IS NOT NULL
AND A.assignment_type = 'E '.
AND A.person_id = papf.person_id
and papf.effective_end_date > sysdate
and a.effective_end_date > sysdate
and (trunc (sysdate) BETWEEN women's wear. EFFECTIVE_START_DATE AND women's wear. EFFECTIVE_END_DATE)
and a.effective_start_date = (select MAX (effective_start_date) from PER_ASSIGNMENTS_f where assignment_id = a.assignment_id)
and a.assignment_id = 42643
and a.assignment_status_type_id = '1')
PIVOT (MAX (screen_entry_value) FOR (name) TO ("Amount" AS 'Amount', 'level' AS 'level', 'Option High' AS 'High Option', 'Pay the value' AS 'Value to pay', 'Period of Type' AS 'Type period'))
order by element_name;
(GOLD)
SELECT ssn,
Employee_number,
employee_full_name,
date_of_hire,
effective_start_date,
element_name,
Max (decode (Name, 'Amount', screen_entry_value)) 'amount. "
Max (decode (Name, 'Level', screen_entry_value)) 'level ',.
MAX (DECODE (name, "High Option", screen_entry_value)) "High Option",
MAX (DECODE (name, 'Value of pay', screen_entry_value)) 'value of pay. "
MAX (DECODE (name, 'Period Type', screen_entry_value)) 'period of Type '.
FROM (select distinct)
' 11-111-1111 "as ssn,
WOMEN'S WEAR. Employee_number,
"Vlad" as employee_full_name,
TO_CHAR (papf.start_date, "MM/DD/YYYY") as date_of_hire
a.effective_start_date,
PETF.element_name,
pivf. Name,
peevf.screen_entry_value
Of
PER_all_PEOPLE_F women's wear
per_assignments_f A
pay_element_types_f petf
pay_element_links_f pelf
PAY_ELEMENT_ENTRIES_F penf
PAY_ELEMENT_ENTRY_VALUES_F peevf
pay_input_values_f pivf
WHERE
PETF.element_name ('Dental Plan before taxes', 'Medical Plan before taxes', "Vision Plan before taxes")
and petf. ELEMENT_TYPE_ID = pelf. ELEMENT_TYPE_ID
and (trunc (sysdate) BETWEEN pelf. EFFECTIVE_START_DATE AND pelf. EFFECTIVE_END_DATE)
and (pelf. ELEMENT_LINK_ID = penf. ELEMENT_LINK_ID and a.assignment_id = penf. ASSIGNMENT_ID)
and (trunc (sysdate) BETWEEN penf. EFFECTIVE_START_DATE AND penf. EFFECTIVE_END_DATE)
and penf. ELEMENT_ENTRY_ID = peevf. ELEMENT_ENTRY_ID
and peevf. INPUT_VALUE_ID = pivf. INPUT_VALUE_ID
AND papf.employee_number IS NOT NULL
AND A.assignment_type = 'E '.
AND A.person_id = papf.person_id
and papf.effective_end_date > sysdate
and a.effective_end_date > sysdate
and (trunc (sysdate) BETWEEN women's wear. EFFECTIVE_START_DATE AND women's wear. EFFECTIVE_END_DATE)
and a.effective_start_date = (select MAX (effective_start_date) from PER_ASSIGNMENTS_f where assignment_id = a.assignment_id)
and a.assignment_id = 42643
and a.assignment_status_type_id = '1')
GROUP BY ssn, employee_number, employee_full_name, date_of_hire, effective_start_date, NOM_ELEMENT
order by element_name;
-
Dear all,
I have a sql like query below
SELECT min (G.TRANSACTION_DATE), D.REQUEST_NUMBER
MTL_TXN_REQUEST_HEADERS D,.
MTL_TXN_REQUEST_LINES, E.
MTL_MATERIAL_TRANSACTIONS G,.
Mtl_Transaction_Types I have
WHERE D.HEADER_ID = E.HEADER_ID
AND G.TRANSACTION_TYPE_ID = I.TRANSACTION_TYPE_ID
AND Upper (I.Transaction_Type_Name) = Upper ('TEC outcome')
AND E.LINE_ID = G.MOVE_ORDER_LINE_ID
AND D.MOVE_ORDER_TYPE = 5
TO_DATE (G.TRANSACTION_DATE) BETWEEN TO_DATE('01-JAN-2014') AND TO_DATE('31-DEC-2014')
D.REQUEST_NUMBER GROUP
I need to get the first number of the application and finally ask for number based on the date of the transaction, how can I get the number of name application and based on the date of the transaction for the same query, please help me.
above query is back under results
If the query should return a line with the number of application like 2383 based on minimum transaction date and another column based on the maximum transaction date, please help me.
so in the example above, it must return
FIRST REQUEST NUMBER LAST NUMBER
2383 1886
Thank you
select min(request_number) keep(dense_rank first order by transaction_date asc ) request_number_min , min(request_number) keep(dense_rank first order by transaction_date desc) request_number_max from ( select min(g.transaction_date) transaction_date , d.request_number from mtl_txn_request_headers d , mtl_txn_request_lines e , mtl_material_transactions g , mtl_transaction_types i where d.header_id = e.header_id and g.transaction_type_id = i.transaction_type_id and upper(i.transaction_type_name) = upper('WIP Issue') and e.line_id = g.move_order_line_id and d.move_order_type = 5 and to_date(g.transaction_date) between to_date('01-jan-2014') and to_date('31-dec-2014') group by d.request_number )
-
Need help with sql query performance
Dear all,
I have a sql like query below, I need to give the following query please help me identify which statement I should tune to have better performanece.
Select rownum LINE_NUM,
A.LINE_ID,
TO_CHAR (A.INVITMID),
TO_NUMBER (A.PICKQTY),
UNLOADINGPNT NULL,
RRNUM NULL,
WORKORDNUM NULL,
WORKORDDESC NULL,
A.PONUM,
DTR_DUMB NULL,
A.DESCRIPTION,
FROM_SUB NULL,
TO_SUB NULL,
NO SOURCE,
ASSET_NUMBER NULL,
A.RECEIPTNUM,
MOVEORD NULL,
FROM_LOC NULL,
TO_LOC NULL,
MSD_NUM NULL,
CONTAIN_LINE NULL,
A.UOM,
A.PO_RELEASE
de)
Select headerid Po.Po_Header_Id,
rcv1. Po_Line_Id LINE_ID,
rcv1.item_id INVITMID,
(NVL(Rcv1.Transact_Qty,0)-NVL(rcv2.transact_qty,0)) PICKQTY,
Po.Segment1 PONUM,
Rcv1.Receipt_Num RECEIPTNUM,
Rcv1.Item_Desc DESCRIPTION,
Rcv1.Transact_Uom GLU,
Rcv1.Po_release
Po_Headers_All in.,.
(Select rcv3. Po_Header_Id, RCV3.receipt_num, rcv3. Po_Line_Id, rcv3. Destination_Type_Code, rcv3. Item_Id, rcv3. Item_Desc, rcv3. Transact_Uom, SUM (rcv3. Transact_Qty) Transact_Qty, rcv3. PO_RELEASE OF)
SELECT A.Po_Header_Id,
C.RECEIPT_NUM receipt_num,
A.Po_Line_Id,
A.Destination_Type_Code,
B.Item_Id,
B.item_description Item_Desc,
A.UNIT_OF_MEASURE Transact_Uom,
A.QUANTITY Transact_Qty,
D.RELEASE_NUM PO_RELEASE
OF RCV_TRANSACTIONS,.
RCV_SHIPMENT_HEADERS C.
B RCV_SHIPMENT_LINES,
PO_RELEASES_ALL D
WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID
AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID
AND UPPER (A.Transaction_Type) = "to DELIVER".
AND higher (A.Destination_Type_Code) = "EXPENSES".
AND D.PO_RELEASE_ID = A.PO_RELEASE_ID
UNION ALL
SELECT A.Po_Header_Id,
C.RECEIPT_NUM receipt_num,
A.Po_Line_Id,
A.Destination_Type_Code,
B.Item_Id,
B.item_description Item_Desc,
A.UNIT_OF_MEASURE Transact_Uom,
A.QUANTITY Transact_Qty,
D.RELEASE_NUM PO_RELEASE
OF RCV_TRANSACTIONS,.
RCV_SHIPMENT_HEADERS C.
B RCV_SHIPMENT_LINES,
PO_RELEASES_ALL D
WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID
AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID
AND B.ITEM_ID IS NULL
AND UPPER (A.Transaction_Type) = "to DELIVER".
AND higher (A.Destination_Type_Code) = "WORKSHOP".
D.PO_RELEASE_ID AND = A.PO_RELEASE_ID) rcv3
GROUP BY rcv3. Po_Header_Id, RCV3.receipt_num, rcv3. Po_Line_Id, rcv3. Destination_Type_Code, rcv3. Item_Id, rcv3. Item_Desc, rcv3. Transact_Uom, rcv3. Rcv1 PO_RELEASE),
(SELECT A.PO_LINE_ID,
Sum (A.Quantity) transact_qty,
A.PO_HEADER_ID,
C.RECEIPT_NUM
OF RCV_TRANSACTIONS,.
RCV_SHIPMENT_HEADERS C.
B RCV_SHIPMENT_LINES,
PO_RELEASES_ALL D
WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID
AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID
AND UPPER (A.Transaction_Type) = "RETURN to the RECEPTION"
AND D.PO_RELEASE_ID = A.PO_RELEASE_ID
A.PO_LINE_ID, A.PO_HEADER_ID, C.RECEIPT_NUM GROUP) Rcv2
Where Po.Po_Header_Id = Rcv1.Po_Header_Id (+)
And Rcv1.Po_Line_Id = Rcv2.Po_Line_Id (+)
And Rcv1.Receipt_Num = Rcv2.Receipt_Num (+)
And Rcv1.Transact_Qty <>Nvl(Rcv2.Transact_Qty,999999999)
Group of po.po_header_id, rcv1.po_line_id, po.segment1, rcv1.receipt_num, rcv1.item_id, Rcv1.Item_Desc, rcv1. TRANSACT_UOM, rcv1. PO_RELEASE, (NVL(Rcv1.Transact_Qty,0)-NVL(RCV2.transact_qty,0))) has
Is my version of the database: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
Please find the attached PLAN to EXPLAIN.
Thank you
May be essentially the same join (between a, b, c and d) twice instead of three times
sounds like it could be done with a single join (between a, b, c, and d), but you do not some columns than the columns of rcv1 rcv2
We can work on what we can see only
Select rownum line_num,
rcv1.po_line_id line_id,
TO_CHAR (rcv1.item_id) invitmid,
NVL(rcv1.transact_qty,0) - nvl(rcv2.transact_qty,0) pickqty,
unloadingpnt null,
rrnum null,
workordnum null,
workorddesc null,
Po. Ponum Segment1,
dtr_dumb null,
description of the rcv1.item_desc,
from_sub null,
to_sub null,
No source,
asset_number null,
rcv1.receipt_num receiptnum,
moveord null,
from_loc null,
to_loc null,
msd_num null,
contain_line null,
Glu rcv1.transact_uom,
rcv1.po_release
of po_headers_all in.
left outer join
(select a.po_header_id,
c.receipt_num,
a.po_line_id,
a.destination_type_code,
b.item_id,
b.item_description item_desc,
a.unit_of_measure transact_uom,
Sum (a.Quantity) transact_qty,
d.release_num po_release
from (select shipment_header_id,
shipment_line_id,
po_release_id,
po_header_id,
po_line_id,
destination_type_code,
unit_of_measure,
quantity
of rcv_transactions
where upper (a.transaction_type) = "to DELIVER".
and upper (a.destination_type_code) ('charge', 'WORKSHOP')
) a
inner join
rcv_shipment_lines b
On a.shipment_line_id = b.shipment_line_id
inner join
c rcv_shipment_headers
On a.shipment_header_id = c.shipment_header_id
left outer join
po_releases_all d
On a.po_release_id = d.po_release_id
where upper (a.destination_type_code) = "EXPENSES".
or (upper (a.destination_type_code) = 'WORKSHOP'
and b.item_id is null
)
A.po_header_id group,
c.receipt_num,
a.po_line_id,
a.destination_type_code,
b.item_id,
b.item_description,
a.unit_of_measure,
d.release_num
) rcv1
On po.po_header_id = rcv1.po_header_id
left outer join
(select a.po_line_id,
Sum (a.Quantity) transact_qty,
a.po_header_id,
c.receipt_num
from (select shipment_header_id,
shipment_line_id,
po_release_id,
po_header_id,
quantity
of rcv_transactions
where upper (a.transaction_type) = "RETURN to THE RECIPIENTS.
) a
inner join
rcv_shipment_lines b
On a.shipment_line_id = b.shipment_line_id
inner join
c rcv_shipment_headers
On a.shipment_header_id = c.shipment_header_id
left outer join
po_releases_all d
On a.po_release_id = d.po_release_id
A.po_line_id group,
a.po_header_id,
c.receipt_num
) rcv2
On rcv1.po_line_id = rcv2.po_line_id
and rcv1.receipt_num = rcv2.receipt_num
where rcv1.transact_qty! = nvl(rcv2.transact_qty,999999999)
Concerning
Etbin
-
Need help with the query (transpose)
Hello experts, please help here - 11 g Oracle, attribute APA APB are fixed values and can be hard coded in query
Need to transpose these data. Max(decode.. perd les données en sortie à cause de la condition de Max.)
Entry:
Name | Attribute | Value
A1 APP 10
A1 PDB 11
A1 APA 20
A1 PDB 21
A2 BPA 13
A2 BPB 14
Expected results:
Name AttVal1 AttVal2
A1 10 11
13 14 A2
20 21 A1
Hello
Here's one way:
WITH relevant_columns AS
(
SELECT name
value
CASE
WHEN the attribute ("APA", "BPA") THEN 1
WHEN the attribute ("PDB", "BPB") THEN 2
END AS c_num
ROW_NUMBER () (PARTITION BY NAME, attirbute
Value of ORDER BY
) AS r_num
FROM table_x
)
SELECT name, attval1, attval2
OF relevant_columns
PIVOT (MAX (value)
FOR c_num IN (1 AS attval1
2 UNDER attval2
)
)
ORDER BY r_num, name
;
If you would care to post CREATE TABLE and INSERT statements for your sample data, and then I could test this.
Why do you want to
NAME ATTVAL1 ATTVAL2
---- ------- -------
A1 10 11
20 21 A1
in the results, rather than
NAME ATTVAL1 ATTVAL2
---- ------- -------
10 21 A1
20 11-A1
? You would be satisfied to one or the other?
Depending on your answer, you may need to modify the analytical ORDER BY clause in the ROW_NUMBER function.
-
Need help with a query of type "connect by level.
Hello, I recently met 'connect by level' and I think he can solve my problem, but maybe not. I would like to create rows of data where the number of rows created varies according to the data from the original table.
It works:
with times like
(select to_date (' 26/01/2014 01:00 ',' dd/mm/yyyy hh24:mi:ss') starttime,)
TO_DATE (' 27/01/2014 00:00:00 ',' dd/mm/yyyy hh24:mi:ss') stoptime
the double)
Select starttime, stoptime, starttime + rownum / 24
of the time
connect by level < =.
(Select trunc ((stoptime-starttime) * 24: 2) at the time)
I would like to do something similar for several lines (following does not work)
with times like
(select to_date (' 26/01/2014 01:00 ',' dd/mm/yyyy hh24:mi:ss') starttime,)
TO_DATE (' 27/01/2014 00:00:00 ',' dd/mm/yyyy hh24:mi:ss') stoptime
of the double
Union
Select to_date (' 25/01/2014 18:00 ',' dd/mm/yyyy hh24:mi:ss') starttime.
TO_DATE (' 27/01/2014 00:00:00 ',' dd/mm/yyyy hh24:mi:ss') stoptime
the double)
Select starttime, stoptime, starttime + rownum / 24
of the time
connect by level < =.
(Select trunc ((stoptime-starttime) * 24: 2) at the time)
I need to stay away from solutions of PL/SQL, this query will be wrapped in an application that can not handle the PL/SQL, going and coming from the database (I also suck in PL/SQL).
Any help would be greatly appreciated, I have no knowledge here, I tried to read some of the documentation on hierarchical queries, but it is not yet clicking.
Thank you!
Or also:
SQL > WITH times
2 ALSO (SELECT TO_DATE (' 01:00 26/01/2014 ', "hh24:mi:ss dd/mm/yyyy") Starttime)
3, TO_DATE (' 01/26/2014 03:00 ', 'hh24:mi:ss dd/mm/yyyy') Stoptime
4 FROM TWO
5 UNION
6 SELECT TO_DATE (' 25/01/2014 18:00 ', "hh24:mi:ss mm/dd/yyyy") Starttime
7, TO_DATE (' 25/01/2014 22:00 ', 'hh24:mi:ss dd/mm/yyyy') Stoptime
8 DOUBLE)
9. SELECT T.*, Starttime + Lvl / 24
10. OF time T
11, (SELECT LEVEL Lvl
THE DOUBLE 12
13 CONNECT BY LEVEL<>
14 (SELECT MAX (TRUNC ((Stoptime-Starttime) * 24)))
15 AT the time)):
16. WHERE the lvl<= trunc="" (="" (stoptime="" -="" starttime)="" *="">=>
17 ORDER 1, 3
18.
STARTTIME STOPTIME-STARTTIME + LVL/24
----------------------------- ----------------------------- -----------------------------
January 25, 2014 18:00 January 25, 2014 22:00 January 25, 2014 19:00
January 25, 2014 18:00 January 25, 2014 22:00 January 25, 2014 20:00
January 25, 2014 18:00 January 25, 2014 22:00 January 25, 2014 21:00
January 25, 2014 18:00 January 25, 2014 22:00 January 25, 2014 22:00
26 January 2014 01:00 26 January 2014 03:00 January 26, 2014 02:00
26 January 2014 01:00 26 January 2014 03:00 January 26, 2014 03:00
6 selected lines.
-
Need help with a query complex for the production database
Hello again,
I need your help once again, for a query how to show me how long each stage of production is by order.
See examples of data and what I expect.
Thank you all for your help.
We use Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
Here the example data tables:
And here's what I expect of my request:CREATE TABLE TABLE_2 ( "ORDER_NR" VARCHAR2 (12) , "PRIORITY" VARCHAR2 (2) , "WO_STEP" VARCHAR2 (1) , "STEP_DATE" DATE ); CREATE TABLE TABLE_1 ( "ORDER_NR" VARCHAR2 (12) PRIMARY KEY , "PRIORITY" VARCHAR2 (2) , "CREATE_DATE" DATE , "ACT_STEP" VARCHAR2 (2) , "STEP_DATE" DATE , "EMPLOYEE" VARCHAR2 (5) , "DESCRIPTION" VARCHAR2 (20) ); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, CREATE_DATE, ACT_STEP, STEP_DATE, EMPLOYEE, DESCRIPTION) VALUES ('1KKA1T205634', '12', TO_DATE('10-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS'), 'U', TO_DATE('28-FEB-13 12:00:00','DD-MON-RR HH24:MI:SS'), 'W0010', 'CLEAN HOUSE'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, CREATE_DATE, ACT_STEP, STEP_DATE, EMPLOYEE, DESCRIPTION) VALUES ('1KKA1Z300612', '12', TO_DATE('08-FEB-13 14:00:00','DD-MON-RR HH24:MI:SS'), 'F', TO_DATE('20-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS'), 'K0052', 'REPAIR CAR'); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', 'A', TO_DATE('12-FEB-13 13:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', '5', TO_DATE('13-FEB-13 09:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', 'K', TO_DATE('13-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', '5', TO_DATE('13-FEB-13 11:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', 'K', TO_DATE('13-FEB-13 12:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', '5', TO_DATE('13-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', 'C', TO_DATE('14-FEB-13 08:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', 'B', TO_DATE('14-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', 'E', TO_DATE('18-FEB-13 13:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', 'F', TO_DATE('20-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', 'S', TO_DATE('21-FEB-13 08:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', 'R', TO_DATE('21-FEB-13 09:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', 'U', TO_DATE('28-FEB-13 12:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1Z300612', '12', 'A', TO_DATE('12-FEB-13 13:52:42','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1Z300612', '12', '5', TO_DATE('13-FEB-13 09:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1Z300612', '12', 'K', TO_DATE('13-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1Z300612', '12', '5', TO_DATE('13-FEB-13 11:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1Z300612', '12', 'K', TO_DATE('13-FEB-13 12:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1Z300612', '12', '5', TO_DATE('13-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1Z300612', '12', 'C', TO_DATE('14-FEB-13 08:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1Z300612', '12', 'B', TO_DATE('14-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1Z300612', '12', 'E', TO_DATE('18-FEB-13 13:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1Z300612', '12', 'F', TO_DATE('20-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS')); COMMIT;
And now the explanation for the result of the query:SYSDATE 28.Feb.13 14:00 ORDER_NR PRIORITYCREATE_DATE STATUS STATUS_DATE DESCRIPTION AGE_1 AGE_2 WAITNG STEP_A STEP_B STEP_C STEP_5 STEP_K STEP_E STEP_F STEP_S STEP_R 1KKA1T205634 12 10.Feb.13 10:00 U 28.Feb.13 12:00 CLEAN HOUSE 18,083 8,833 2,125 0,833 4,125 0,083 0,750 0,208 2,125 0,666 0,042 7,125 1KKA1Z300612 12 08.Feb.13 14:00 F 20.Feb.13 16:00 REPAIR CAR 20,000 16,042 2,125 0,833 4,125 0,083 0,750 0,208 2,125 0,666
The AGE_1 is the difference in days between the "CREATE_DATE" and if EXSIST L'ETAPE 'U' then STEP_DATE or if the STEP 'U' is not found in TABLE_2 then it should show the difference in days between the "CREATE_DATE' and the 'SYSDATE.
The AGE_2 is the difference in days between the STEP "A" STEP_DATE and IF EXSIST L'ETAPE 'R' then STEP_DATE or if the STEP 'R' is not in TABLE_2 then it should show the difference in days between the "CREATE_DATE' and the 'SYSDATE.
The EXPECTATION is the difference in days between CREATE_DATE and STEP 'A' STEP_DATE
The following columns indicate the days, how long the ORDER_NR remains in these TIMES, if an ORDER_NR comes in the same STEP should be calculated together more than once.
If the ORDER_NR jump a step, it should show a zero in the specific field.
I hope that my explanation is good enough, my English skills are far from good.
Thank you for all your help.
Hosts Reinhard W.Solomon Yakobson says:
Just add the amounts:In fact, you could edit all CASES:
with t2 as ( select t.*, lead(step_date) over(partition by order_nr order by step_date) next_step_date from table_2 t ) select t1.*, nvl( max( case t2.wo_step when 'U' then t2.step_date end ), sysdate ) - t1.create_date age_1, nvl( max( case t2.wo_step when 'R' then t2.step_date end ), sysdate ) - t1.create_date age_2, sum( case when t2.wo_step in ('B','5') then t2.next_step_date - t2.step_date end ) step_b_5, sum( case t2.wo_step when 'C' then t2.next_step_date - t2.step_date end ) step_c, sum( case t2.wo_step when 'K' then t2.next_step_date - t2.step_date end ) step_k, sum( case t2.wo_step when 'E' then t2.next_step_date - t2.step_date end ) step_e, sum( case t2.wo_step when 'F' then t2.next_step_date - t2.step_date end ) step_f, sum( case t2.wo_step when 'S' then t2.next_step_date - t2.step_date end ) step_s, sum( case t2.wo_step when 'R' then t2.next_step_date - t2.step_date end ) step_r from table_1 t1, t2 where t2.order_nr = t1.order_nr group by t1.order_nr, t1.priority, t1.create_date, t1.act_step, t1.step_date, t1.employee, t1.description / ORDER_NR PR CREATE_DA AC STEP_DATE EMPLO DESCRIPTION AGE_1 AGE_2 STEP_B_5 STEP_C STEP_K STEP_E STEP_F STEP_S STEP_R ------------ -- --------- -- --------- ----- ----------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 1KKA1T205634 12 10-FEB-13 U 28-FEB-13 W0010 CLEAN HOUSE 18.0833333 10.9583333 4.875 .083333333 .208333333 2.125 .666666667 .041666667 7.125 1KKA1Z300612 12 08-FEB-13 F 20-FEB-13 K0052 REPAIR CAR 44.252338 44.252338 4.875 .083333333 .208333333 2.125 SQL>
SY.
-
NEED HELP WITH THE QUERY, NEED MORE RECENT FILE ONLY
Hi all
That is,
I have an assignment I need to find agents that allow players to break the rules.
So far, I have 41 results, in which there are 4 principles and 24 footballers and football player even beat more than one rule or the rule more than once.
What I need now is to make arrangements so that every footballer appears once n matter how many times they have broken the rules.
I have
SELECT
t.transfer_time | ' ' || a.first_name | ' ' || a.last_name | ' ' || f.first_name | ' ' || f.last_name | ' ' || f.footballer_id | ' ' || t.transfer_id
Of
agents a, t transfers, footballers f, footballers_fees fo
WHERE
a.agent_id = t.broker_id
AND
t.footballer_id = f.footballer_id
AND
f.footballer_id = fo.footballer_id
AND
(RULE 1 BROKEN AND RULE 2 BROKEN
OR
RULE 1 BROKEN AND ARTICLE 2 DOES NOT DECOMPOSE
OR
RULE 1 DOES NOT DECOMPOSE AND RULE 2 BROKEN)
GROUP BY
t.transfer_time | ' ' || a.first_name | ' ' || a.last_name | ' ' || f.first_name | ' ' || f.last_name | ' ' || f.footballer_id | ' ' || t.transfer_id
ORDER BY
t.transfer_time | ' ' || a.first_name | ' ' || a.last_name | ' ' || f.first_name | ' ' || f.last_name | ' ' || f.footballer_id | ' ' || t.transfer_id
;
(I did not type the SQL code to rules 1 and 2 but I know it works)
Now, I need not to show that every footballer once they broke rule and more than once or not.
I was looking at the screen nearly enough hours 10 and any help or ideas would be greatly appreciated
Thank you all :)Hello
Welcome to the forum!
Whenever you have a problem, please post a small example of data (CREATE TABLE and INSERT statements) so that people who want to help you can recreate the problem and test their ideas. You don't have to display a large amount of data. In this case, it seems that 2 to 10 lines for each table could give a good picture of the problem.
After the results that you want samples fropm, and explain how you get those resulting from these data.
Always tell what version of Oracle you are using.The ideal outcome would be just what you '; Re I get now, but with some deleted rows and only 1 line by left footballer? If so, do a subquery on the original query, and then add somehting like
, ROW_NUMBER () OVER (PARTITION BY f.footballer_id ORDER BY NULL) AS r_num
in the SELECT clause.
then, in the main query, display only linesWHERE r_num = 1
ROW_NUMBER requires an ORDER byclause of analytics. If you ORDER BY a constant (e.g. NULL) then what line gets number 1 will be arbitrary. If you care who lines for a given player is numbered 1 (and therefore included in the final output), then adjust the analytical ORDER BY clause. (You the title mentions "most recent record only", so if the dt column indicates whether a line is "newer" than another, you can "ORDER BY dt DESC".)
I know this response is vague in places. Without a concrete example (CREATE TABLE and instructions INSERT for examples of data and outcomes from these data), that's the best I can do.
-
Need help with SQL Query - change of name history of audit table.
I need your help to find the result in the following way...
Emp No New_name Old_Name ----------------------------------------------- 1 Name3 Name2 1 Name2 Name1
Thank you...create table emp(emp_id number(10), emp_name varchar(50), constraints emp_pk primary key(emp_id) ); create table emp_audit( audit_id number(10), emp_id number(10), emp_name varchar(50), audit_date date, constraints emp_audit_pk primary key (audit_id), constraints emp_audit_emp_fk foreign key(emp_id) references emp(emp_id)); insert into emp values(1,'Name3'); insert into EMP_AUDIT (audit_id, emp_id, emp_name, audit_date) values (1, 1, 'Name1', to_date('14-08-2011', 'dd-mm-yyyy')); insert into EMP_AUDIT (audit_id, emp_id, emp_name, audit_date) values (2, 1, 'Name2', to_date('15-08-2011', 'dd-mm-yyyy')); commit;
Dipabkar Bédard (DB) wrote:
We write is the query without using "partition by" in oracle...?
with t as ( select audit_id, emp_id, emp_name, row_number() over(order by audit_id) rn from emp_audit order by emp_id, audit_id ) select a.audit_id, a.emp_id, a.emp_name old_name, nvl(b.emp_name,(select c.emp_name from emp c where c.emp_id = a.emp_id)) new_name from t a left join t b on ( b.emp_id = a.emp_id and b.rn = a.rn + 1 ) / AUDIT_ID EMP_ID OLD_NAME NEW_NAME ---------- ---------- -------------------------------------------------- ------------ 1 1 Name1 Name2 2 1 Name2 Name3 SQL>
And without analytical functions:
with t1 as ( select audit_id, emp_id, emp_name from emp_audit order by emp_id, audit_id ), t2 as ( select audit_id, emp_id, emp_name, rownum rn from t1 ) select a.audit_id, a.emp_id, a.emp_name old_name, nvl(b.emp_name,(select c.emp_name from emp c where c.emp_id = a.emp_id)) new_name from t2 a left join t2 b on ( b.emp_id = a.emp_id and b.rn = a.rn + 1 ) / AUDIT_ID EMP_ID OLD_NAME NEW_NAME ---------- ---------- -------------------------------------------------- ---------- 1 1 Name1 Name2 2 1 Name2 Name3 SQL>
SY.
-
Need help with the query using the AVG function
First post here.
I am a student taking a SQL class and I can't find a query.
I think I'm close to get it, but I can not quite all the way there.
Three tables are involved in this problem. Here is a list of the tables and the areas concerned:
Problem:orders table: order# shipstate orderitems table: order# isbn quantity (How many copies of book purchased on that order) books table: isbn retail (retail price of book)
I want to get an average of "total amount" by shipstate.
For example, in these tables, there are 8 records of the State of Florida.
However, there are only 5 unique order # for this State.
The amount of detail * quantity for these 8 disks (or 5 orders) is $345,10
Now to get my average $345,10 should be divided by 5. (number of unique commands)
In the following query it divides this $345,10 8. (number of records)
How to make this request to divide by the number of unique order # rather than the number of records?
According to me, once I get this part down, I can understand the rest of the problem.SELECT shipstate, AVG(quantity * retail) FROM orders JOIN orderitems USING (order#) JOIN books USING (isbn) GROUP BY shipstate HAVING SUM(quantity * retail) =ANY (SELECT SUM(quantity * retail) FROM books JOIN orderitems USING (isbn) JOIN orders USING (order#) GROUP BY shipstate)
The end result, I need, is to find all the individual commands that have a "total amount due" that is greater than the 'average amount due' for this state of clients.
Any help, suggestions or comments welcome.
MattYour average take into account the shipstate (8 disks), you can do that for the expected results.
With some examples of input data it would be easier, but here a try:SELECT shipstate, sum(quantity * retail)/count(distinct order#) FROM orders JOIN orderitems USING (order#) JOIN books USING (isbn) GROUP BY shipstate;
Nicolas.
delete the alias
Edited by: N. Gasparotto on October 3, 2008 19:28 -
Need help with the query to get the County
Hello
Oracle 10 g 2 10.2.0.3 - 64 bit
I want back the number of accounts with two different types of funds (say A and B). Some accounts hold only one of the two funds, and some support both. I want to get the counts like this:
- account held funds - has only
- accounts holding funds-B only
- accounts holding the Fund-A and B funds
Here is what I started with but need assistance to meet the requirement above:
select count(distinct acct.bkoff_acct_no ) accounts_holding_fund_A from xe_account acct, xec_tal_investment_mandate iman, xec_tal_asset_allocation alloc, xe_benchmark bmark, xe_benchmark_usage bu, xe_object_description xod, xec_asset_class cls where iman.mandate_status_cd='A' and cls.asset_class_cd = alloc.asset_class_cd and iman.mandate_id = alloc.mandate_id and acct.account_id = iman.object_id and iman.object_type_cd = 'ACCT' and iman.mandate_id = xod.object_id and xod.field_nm='XEC_TAL_INVESTMENT_MANDATE.COMMENT_TXT' and xod.language_cd = 'E' and acct.acct_status_cd = 'O' and bu.object_type_cd(+) = 'TMAA' and bu.object_id(+) = alloc.asset_allocation_id and bmark.benchmark_id(+) = bu.benchmark_id and alloc.resp_txt like '%fund-A%'
And suppose that the Fund-B has resp_txt like ' % of Fund-B»
Please suggest.
Concerning
Hello
Here is another way, it is easier to adapt to different jobs and different numbers of jobs:
WITH got_distinct_jobs AS
(
SELECT DISTINCT deptno, job
FROM scott.emp
WHERE job IN ("ANALYST", "CLERKS") - or what
)
got_job_list AS
(
SELECT LISTAGG (job, ",") THE Group (ORDER BY work) AS job_list
OF got_distinct_jobs
GROUP BY deptno
)
SELECT job_list
COUNT (*) AS num_departments
OF got_job_list
GROUP BY job_list
;
This shows all the combinations of the jobs listed in the WHERE clause of got_distinct_jobs. You don't need to change anything else in the query. There may be any number of jobs.
Output:
JOB_LIST NUM_DEPARTMENTS
------------------------------ ---------------
CLERK 2
ANALYST, CLERK 1
-
Need help with a query complex
ID Col1 Col2 COL3 COL4 VAL 1 col1_1 col2_1 col3_1 col4_1 val1 1 col1_1 col2_1 col3_1 * val2 1 col1_1 col2_1 * * val3 1 col1_1 * * * Val4 1 * * * * Val5 I want to get the result.
Col1, col2, col3, col4 will be entered and I need to find the Val by matching the Col1, col2, col3 col4.
IF there is no match for any column, then it should consider it as *.
So basically for any value of Col1, col2, col3, col4, it should return Val.
Example - he must return val1 for col1_1, col2_1, col3_1, col4_1
and val5 for col1_11, col2_11, col3_11 and col4_11 have no match for all 4 columns here.
How to write a simplified in this case request? any help is really appreciated.
SQL > with t as)
2. Select val,
3 dense_rank() on)
4 order of col1 case when ' *' then 0 end of another 1 +.
5 case col2 where ' *' then 0 end of another 1 +.
6 case col3 where ' *' then 0 end of another 1 +.
7 case col4 when ' *' 0 then 1 other side desc
8 ) rnk
9 of tbl
10 where col1 in ('col1_1','* ')
11 and col2 in ('col2_1','* ')
12 and col3 in ('col3_1','* ')
13 and col4 in ('col4_1','* ')
14 )
15 select val
16 t
where the 17 rnk = 1
18.VAL
----
val1SQL > with t as)
2. Select val,
3 dense_rank() on)
4 order of col1 case when ' *' then 0 end of another 1 +.
5 case col2 where ' *' then 0 end of another 1 +.
6 case col3 where ' *' then 0 end of another 1 +.
7 case col4 when ' *' 0 then 1 other side desc
8 ) rnk
9 of tbl
10 where col1 in ('col1_11','* ')
11 and col2 in ('col2_11','* ')
12 and col3 in ('col3_11','* ')
13 and col4 in ('col4_11','* ')
14 )
15 select val
16 t
where the 17 rnk = 1
18.VAL
----
Val5SQL >
SY.
-
Hello
I have a customer as requirement below
We have the table header and contains data such as
ID, custname, socket
101, raju, 514
102, ratna, 12
103, rakesh, 16
104, joseph, 129
and we mappingtable like below as
sampval, socket
244094,512
244095,2
244096,4
244097,8
244098,16
244102,128
244103,1
If header.mapvalue is 514 analysis then it out on the mappingtable basis to be exported for a value of 244094. 244095.
Header.mapvalue is 12 parsing it out based on mappingtable to be exported for a value of 244096. 244097 and so on...
Could you please help me how to get the functionality in a database query.
Thanks in advance
Try to query below and let me know
SELECT id,
custName,
HT.mapvalue,
req_val
From ht header_tbl,
(SELECT SAMPVAL,
socket,
CITY,
SUMVAL,
REQ_VAL
Of
(SELECT SAMPVAL,
socket,
CITY,
SUMVAL,
REQ_VAL,
ROW_NUMBER() over (ORDER BY lvl SUMVAL PARTITION) rn
Of
(SELECT sampval,
socket,
City,
LEVEL lvl,
CASE
WHEN ((= LEVEL 2)
AND (socket = socket connect_by_root))
THEN socket
ANOTHER socket + connect_by_root socket
END as sumval,
CASE
WHEN ((= LEVEL 2)
AND (socket = socket connect_by_root))
THEN TO_CHAR (sampval)
Of OTHER TO_CHAR (CONNECT_BY_ROOT sampval
||'|'
|| sampval)
END AS req_val
A mapping
CONNECT BY LEVEL<=>=>
)
WHERE the lvl = 2
)
WHERE rn = 1
) qry_rslt
WHERE ht.mapvalue = qry_rslt.sumval;
An alternative with xmlagg, you can use this query to achieve your requirement
SELECT id, custname, RTRIM (xmlagg (xmlelement(e,mp.sampval||'|')). Extract ('//Text ()'),'| ') req_val
From header_tbl, mapping mp ht
WHERE mp.mapvalue = BITAND (mp.mapvalue, ht.mapvalue)
GROUP BY id, custname;
Maybe you are looking for
-
Worm. 13 takes 2.1 GB of memory, and then not turning page.
On my Kubuntu system, I've upgraded to version 13 and started having big problems.I tried to reset it using 'Troubleshooting Information' then ' Reset Firefox to.its default state'. I still have a lot of problems. As much as I need toKonqueror allows
-
online media, absent on the media library How to I put online media and program libuary on the Media Center, I have everything expect those two, they are absent
-
How can I me Wizard scan windows to recognise a scanner wireless
I just bought a wireless scanner, epson software sees the scanner but scanner windows Wizard will not see it, y at - it something that I did not?
-
System File Checker does not seem to fix corrupt files.
I ran sfc/scannow and at the end he said he found and repair corrupt files. However if I run a second or third or 4th time it always says the same thing as if corrupted files were not repaired.
-
Hang Z10 Z10 blackBerry to 100% at the start
My phone this morning seems to be stuck at 100% loading screen. -I did not a reboot, the phone was last night and this morning, he is discovered to be stuck -a out the battery and put it again, the boot process is again stuck at 100% -the phone was o