Need help with sql query involving distinct and County
I have 2 tables and I want to get the number of specific names. Find the details below. It's hard to explain but I will try to provide as much detail as I can.Table A:
ID of the SR
1001 1
1002 2
2 1003
1004 3
Table B:
Name of the key SrNew
1 David 1001
2 James 1002
3 James 1002
4 James 1003
5 James 1004
6 Mike 1004
Result: I'm looking:
Count names such as if the name appears for the same ID of Table A two times, and then only count 1.
Name of County
David 1
James 2 (1002 and 1003 for the same ID (ID #2) so count as 1 for this and then 1 more for 1004 and ID 3)
1 Mike
I have following question:
SELECT distinct (b.Name), a.ID
FROM TableA, TableB b
Where a.Sr = b.SrNew Group By b.Name, a.ID
and as a result I get:
ID name
David 1
James 2
3 James
3 Mike
Now, I want to just the number of each name with the result, but don't know how I can do this with a sql?
Thanks in advance.
Who help me?
SELECT b.Name, count(distinct a.ID)
FROM TableA a, TableB b
Where a.Sr = b.SrNew
Group By b.Name
Nicolas.
Tags: Database
Similar Questions
-
need help with sql query dates
Hello
I have a sql query I need to extract some info between data dates. Where clause in this query is:
WHERE CPD_BUS_UNIT =: ESI_PRM_1
AND CPD_VOUCHER_DATE > =: P_DATE_FROM
AND CPD_VOUCHER_DATE < (: P_DATE_TO + 1).
When I run the query into a toad, I can view the data, but not the execution plan. It gives an error ORA-00932 inconsistent Datatypes.
But when I remove (+ 1): P_DATE_TO, I can c the execution plan and data. The data will be different from the previous.
Please suggest how to rewrite the query.Can you please give it a try?
WHERE CPD_BUS_UNIT=:ESI_PRM_1 AND CPD_VOUCHER_DATE >= :to_date(P_DATE_FROM) AND CPD_VOUCHER_DATE < (to_date(:P_DATE_TO)+1)
Concerning
-
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 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 SQL query (10 years since I have SQL)
Hi guys,.
I tried to remove some rust SQL. I did not go to SQL within a certain time.
Here are the tables (% = ent $ = varcchar)
-----------------
RESULT
-----------------
% RESULT_ID-$ RC-% YEAR_ID - PERIOD_ID-% CONTRACT_NO-% value %
20841---1439---83---37---010427102---1
20842---1439---83---41---010427102---2
20843---1439---84---37---010427102---3
20844---1439---84---41---010427102---4
20845---1439---83---34---010427102---5
-----------------
YEARS
-----------------
YEAR_ID - YEAR_DESC
83 2010-2011
84 2011-2012
-----------------
PERIOD
-----------------
PERIOD_ID - PERIOD_DESC
34 14
37 02
41 03
What I want is to get the last period of each year in the RESULT table. (I'll work the rest of the WHERE statement myself, because I have omitted some news, or columns for simplicity)
Note that I can't rely on the ID of the period, as the chronological order is not respected.
In the scenario above, I should GET
% RESULT_ID-$ RC - YEAR_ID - PERIOD_ID-% CONTRACT_NO-% % value %
20844---1439---84---41---010427102---4
20845---1439---83---34---010427102---5
I have the following, but it only returns values if the year is the last time!
SELECT DISTINCT RESULTS. RESULT_ID, RESULT. RC, RESULT. PERIOD_ID, RESULT. YEAR_ID, RESULT. CONTRACT_NO, YEARS. YEAR_DESC
RESULT, YEARS
WHERE TO TRAIN. YEAR_ID = YEARS. YEAR_ID AND - it is my problem, I want the last period for each year.
RESULT. PERIOD_ID = (SELECT PERIOD_ID FROM PERIOD WHERE CAST (PERIOD_DESC AS INT) = (Select MAX (CAST (PERIOD_DESC AS INT)) of the period)) - I think it works fine I'm able to get the last period
ORDER BY YEARS. YEAR_DESC;
Published by: 935079 on May 17, 2012 11:32
Add space not formatted tabs
Published by: 935079 on May 17, 2012 11:35Your way to present the data that makes it very tedious to create test data. Next time please simply provide CREATE TABLE and INSERT statements so that we can all share the same test data.
Without test data, I think you want Frank solution with a very minor change: order value instead of id, then the number of line 1 is the highest value.
with GOT_R_NUM as ( SELECT r.* -- or list the columns you want , ROW_NUMBER() over(partition by R.YEAR_ID, R.CONTRACT_NO order by -- P.PERIOD_ID P.PERIOD_VALUE DESC NULLS LAST) AS r_num FROM result r JOIN period p ON r.period_id = p.period_id ) SELECT * -- or list all columns except r_num FROM got_r_num WHERE r_num = 1;
-
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
-
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 SQL/PL/SQL for Dates
Hi Experts - need help with a SQL query.
I need to insert some date fields in a table called CALENDAR_PERIOD.
Current data in CALENDAR_PERIOD table with their data types:
STARTPERIOD (DATE) YEAR (NUMBER) PERIOD_LABEL (Varchar2 255)
02/11/2014 2014 2014/02/11 SUN
03/11/2014 2014 14/03/11 MON
04/11/2014 2014 11/04/14 MAR
I have to increment above values up to the year 2025. I don't know how to write SQL and increment of these values.
Ex: My next value should insert: 05/11/2015 2014 11/05/14 WED like that I need to insert data until 12 31, 2025.
Can you please help me with PL/SQL block?
Really appreciate your help!
DB version:
Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE Production 11.2.0.3.0
AMT for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
Thank you
SandyHello Sandy,
Maybe something like
INSERT INTO calendar_period (startperiod, year, period_label)
SELECT DATE '' 2014-11-04 + LEVEL
, TO_NUMBER (TO_CHAR (DATE '' 2014-11-04 + LEVEL, "YYYY"))
, TO_CHAR (DATE '' 2014-11-04 + LEVEL, "MM/DD/YY DY")
OF the double
CONNECT BY LEVEL<= date="" '2025-12-314="" -="" date="">=>
;
((mais je ne comprends pas pourquoi nous créons une telle table "année" et "period_label" peuvent être calculé à partir de startperiod))
Best regards
Bruno Vroman.
-
Under Update taking 2 h complete 3000 sets.
UPDATE ARR_TRANSACTIONS ARR
SET = NUMBER99
(SELECT ARR_1.NUMBER99
OF ARR_TRANSACTIONS ARR_1, ARR_HEADER BH
WHERE ARR_1.ARR_ID = BH. ARR_ID
AND BH. FLAG = "Y".
AND ARR_1.LINE_ID = ARR. ORIG_INV_LINE_ID
AND ARR_1.NUMBER9 IS NOT NULL
AND ROWNUM = 1)
WHERE ARR BATCH_ID = 26219
AND ARR. NUMBER99 IS NULL
I added more some condition where to reduce cost and its working fine. But I need to rise more than performance on SQL.
Please help with SQL.
I do not see the number of 3000 lines in the plan - so I guess that the optimizer does not compute with the correct numbers. Could generate the plan with dbms_xplan.display_cursor? This could tell us something about filter predicates and access.
In the given situation, I would check:
- is the access to the index in step 1 (filtered by the relevant conditions: this could be BATCH_ID = 26219) return actually 248 entries (or something similar)?
- Access table in step 2 returning 204 lines (or something similar) after applying the filters given? If the number of lines is much bigger then a Nested Loops is perhaps not a good idea.
To make this much simpler check, you could create a plan with statistics of content (RowSource) given that the plan containing the real and the number of estimated rows.
If the estimated cardinalities are not plausible the next question would be if the statistics are strong and up to date.
-
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 Sprite´s. (Rectangles and circle)
Hello!
I kinda need help with a project. I m supposed to do a script that responds to a click and moves the circle of one rectangle to another.
(Here's a picture)
So, what I want is: when I click on the blue rectangle to the right, the circle must move instantly in the rectangle on the right. And same thing on the opposite path.
Thanks in advance!
-Best regards,.
Aleksandar "Dyxir" B.
import flash.events.MouseEvent;
leftRec.addEventListener (MouseEvent.CLICK, fCircle);
rightRec.addEventListener (MouseEvent.CLICK, fCircle);function fCircle(evt:MouseEvent)
{
Circle.x = evt.currentTarget.x;
Circle.y = evt.currentTarget.y;
}Note: Point for all alignment: Center
-
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;
-
Help with SQL Query (Subselects)
Hello community,
IAM a new Member in this forum. The first excuse my English, my native language is German.
In my workplace, we have a great Orcle Database 11 g with 30 different tables for production control issues.
I try to get a couple of different information from the database, so I started with SQL of the query, but for this problem, I wasn't able to write a query to work.
In this case, I have 2 tables:
Table 1:
ID; ORDER_NR; DESCRIPTION; CREATE_DATE
1; A500236; CLEAN HOUSE; 20/02/2012
2; A623555; REPAIR CAR; 10/01/2012
3; A866944; MAINTAIN EQUIPMENT; 11/02/2012
Table 2:
ID; ORDER_NR; WO_STEP; STEP_DATE; EMPLOYEE
1; A500236; A; 21/02/2012; W0010
2; A500239; F; 21/02/2012; W0010
3; A500239; S; 22/02/2012; W0027
4; A500239; R; 23/02/2012; H0034
5; A500239; U; 25/02/2012; L0099
6; A263555; A; 15/01/2012; G0009
7; A263555; C; 17/01/2012; S0039
5 V A263555; R; 18/01/2012; K0059
9; A263555; U; 19/01/2012; A0048
10; A866944; A; 13/02/2012; H0034
11; A866944; B; 13/02/2012; L0035
12; A866944; G; 17/02/2012; D0084
13; A866944; U; 23/02/2012; S0039
And the result of my query should look like this:
ORDER_NR; DESCRIPTION; CREATE_DATE; A_STAT_AGE; R_STAT_AGE; U_STAT_AGE
A500236; OWN HOME; 20/02/2012; 5; 3; 1
A623555; REPAIR CAR; 01/10/2012; 42; 39; 38
A866944; MAINTAIN EQUIPMENT; 11/02/2012; 15; 4; 3
The age of my query result should be calculated from the date of the creation of the order.
I would like to know 2 things, one is how old was the order when they reached this status, R and U.
The second, that is, how long did you order remaining on A stat, R and U (and if possible all the others too)
It can happen that not every order reaches every State, so he ca go directly from A you in this case I want to display a generic character in this row/column
I hope you all know what I mean and what result to expect.
Thanks for your help.
Reinhard W.Hi, Reinhard,
990524 wrote:
Hi Frank,.I thank you for your professional response and excuse my non-professional way to clarify my question.
I have now already read and understand how to ask good questions, but is there an easy an inexpensive way to run a database on my computer at home?You can download the Oracle database from this site. The Express edition is easier to install. It lacks a few features that the Enterprise edition (for example, partitioning table and safety of level line), but most of the things work in all editions of Oracle.
All editions are free if you do not use them for Production applications. Of course, at this price (or lack thereof), you get Oracle support.I have already noticed that the syntax SQL for Oracle differ from other DBMSS.
Yes and some features are different in different products.
Your query works perfectly, thank you.
Now I want to refine my (your) query, is there a way to display a range of day within 1 day? As 0.5 day to half a day between two State timestamp.
Of course, you can do it. After the exact output desired of the sample data that I posted. If the sample data do not show what you need to do, then after a few different examples of data that makes.
My table contains the Date and time in a row, I forgot to mention that.
After a CREATE TABLE statement. I was guessing a lot of things that may be important. For example, I assumed you were using a DATE for date and time column. So it is only reasonable to do so, but maybe it's not what looks like at your table.
I tried something like this:
SYSDATE - MIN ( CASE WHEN t2.wo_step = 'A' THEN t2.step_date END ) AS Age_A
But it gives me an error of arithmetic overflow and not die difference in the Date and time or days with decimal friction.
There are only about 5.4 million possible days with DATEs of Oracle. Is only 7 digits and Oracle can treat approximately 39 numbers without overflow errors, so I don't see how this can happen if t2.step_date is really a DATE. This is an example of why you need to publish a CREATE TABLE statement.
-
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.
Maybe you are looking for
-
Hello I hope you are not tired IPhone 6 I have, with stolen boxes I hope that the Apple ID, help me find my phone IMEI Please help me make
-
my cd player is unable to register but can play only.why?
I can't take back up on top of the cd player, but it only reads.
-
HAVE WINDOWS 7 PRO BUT LOST CD
Lost CD I bought with my computer. My computer has been altered. The it Department had only Windows 7 Home version. I don't have the product key for the operating system Windows 7 Professional. Microsoft could help me restore the OS Windows7Pro or th
-
What windows 7 to a new hard drive?
My hard drive went down hard so I can't access it. The machine had xp on it, but since I have to get a new hard drive, I want to put W7 on it. I've seen towing of W7 disk types. on intended for sale with a new pc and the other intended to be distribu
-
Audio for Windows 7 to cancel everything at stake
Windows 7 Pro EVGA X 58-class 3 E770 EVGA GTX 570HD 2.5 GB/1.2 PhsyX Intel Core i7 950 Corsair AX1200i Corsair H80i Corsair K95 Razer Mamba 2012 Map its Creative Sound Blaster Fatal1ty X - Fi Titanium Logitech Z-5500 5.1 Surround In the last days of