Qusetion SQL please
Hi allI want to run this query, for example in the SCOTT user please
I want to retrieve ename, deptno, max (sal) to emp and display the max and deptno sal and the name of the person who will get the max sal that I am trying to do this
{select ename, deptno, max (sal) of emp
Group of ename, deptno}
It will give me below
ENAME, DEPTNO MAX (SAL)
---------- ---------------------- ----------------------
SMITH 20 800
20 2975 JONES
FORD 3000 20
2450 10 CLARK
20 3000 SCOTT
TURNER 30-1500
JAMES 30 950
KING 10 5000
20 1100 ADAMS
30 2850 BLAKE
10 1300 MILLER
30 1600 ALLEN
WARD 30 1250
30 1250 MARTIN
but my question is what is the name that will get the sal max... Please help me with this
I mean the result below
Ename, deptno max (sal)
10 3000 SCOTT
FORD 5000 20
30 1600 ALLEN
Published by: khalidoracleit on July 6, 2010 04:22
select b.empno, b.ename, a.sal, a.deptno
from emp b, (select deptno, max(sal) sal
from emp
group by deptno) a
where a.sal = b.sal and
a.deptno = b.deptno
Tags: Database
Similar Questions
-
error of dynamics of the associative array (pl/sql), please help
Function down I can hard-coded but not able to go to dynamically can u please friends
CREATE OR REPLACE FUNCTION FN_SUBSCRIPTION_BEHAVIOUR(P_YYMM IN VARCHAR2) RETURN VARCHAR2
AS
ARR_LIST APEX_APPLICATION_GLOBAL. VC_ARR2;
Typ_array. ARRAY TYPE IS VARCHAR2 (16);
array_final typ_array;
V_ARRAY VARCHAR2 (2000);
v_out VARCHAR2 (2000);
v_result VARCHAR2 (2000);
BEGIN
ARR_LIST: = APEX_UTIL. STRING_TO_TABLE (P_YYMM, ',');
Select LISTAGG (fid_value, ',') IN GROUP (ORDER BY fid_value) BY v_array
of filter_detail, filter_master
where fil_id = fid_fil_id
and fil_position = 15
AND NVL (fid_ACTIVE, 'Y') = 'Y ';
array_final: = typ_array (v_array); Commented (1102,1101,1012,1011,1010,1009,1008,1007,1006,1005,1004,1003,1002,1001);
I'm looping 1.array_final.count
If array_final (i) in (arr_list (I)) then v_result: = '1';--Commented--(1002,1003,1007)
Another v_result: = '0';
end if;
v_out: = v_out | v_result;
end loop;
Return v_out;
END;
my output is
00000001000110
Published by: V on March 23, 2011 21:42
Published by: V on March 23, 2011 22:24
Published by: V on March 23, 2011 23:00
Published by: V on March 24, 2011 12:57 AMHello
Please check below, hope this helps.
SQL> SQL> DROP TABLE tmp 2 / Table dropped SQL> CREATE TABLE tmp ( col1 NUMBER) 2 / Table created SQL> INSERT INTO tmp 2 SELECT 1001 FROM DUAL UNION 3 SELECT 1002 FROM DUAL UNION 4 SELECT 1003 FROM DUAL UNION 5 SELECT 1004 FROM DUAL UNION 6 SELECT 1005 FROM DUAL UNION 7 SELECT 1006 FROM DUAL UNION 8 SELECT 1007 FROM DUAL UNION 9 SELECT 1008 FROM DUAL UNION 10 SELECT 1009 FROM DUAL UNION 11 SELECT 1010 FROM DUAL UNION 12 SELECT 1011 FROM DUAL UNION 13 SELECT 1012 FROM DUAL UNION 14 SELECT 1101 FROM DUAL UNION 15 SELECT 1102 FROM DUAL 16 / 14 rows inserted SQL> COMMIT 2 / Commit complete SQL> CREATE OR REPLACE FUNCTION FN_SUBSCRIPTION_BEHAVIOUR(P_YYMM IN VARCHAR2) 2 RETURN VARCHAR2 AS 3 ARR_LIST APEX_APPLICATION_GLOBAL.VC_ARR2; 4 TYPE typ_array IS TABLE OF VARCHAR2(16); 5 array_final typ_array; 6 V_ARRAY VARCHAR2(2000); 7 v_out VARCHAR2(2000); 8 v_result VARCHAR2(2000); 9 BEGIN 10 select LISTAGG(col1, ',') WITHIN 11 GROUP( 12 ORDER BY col1) 13 INTO v_array 14 from tmp; 15 ARR_LIST := APEX_UTIL.STRING_TO_TABLE(v_array, ','); 16 for i in 1 .. ARR_LIST.count loop 17 if (INSTR(P_YYMM, ARR_LIST(i)) > 0) then 18 v_result := '1'; 19 else 20 v_result := '0'; 21 end if; 22 v_out := v_out || v_result; 23 end loop; 24 return v_out; 25 END; 26 / Function created SQL> DECLARE 2 l_out VARCHAR2(2000); 3 BEGIN 4 l_out := FN_SUBSCRIPTION_BEHAVIOUR('1002,1003,1004'); 5 dbms_output.put_line(l_out); 6 END; 7 / 01110000000000 PL/SQL procedure successfully completed SQL>
Ameya
-
I have a question in the document oracle certificate and they give the solution with it included, so the question is
Evaluate the SQL statement:
Select LPAD (salary, 10, *) from emp where emp_id = 1001;
If the employee with 1001 EMP_ID has a salary of 17000, what is displayed?
A.17000.00
B.17000* *.
C. * 170.00
D. * 17000.00
E. a statement error
And they give the solution is C
But I think it's WRONG because it takes the E because * must have ' *', because it is question of certificate Oracle and if I add to the query (and salary = 17000) his will give anything you agree with me?Yes, you are right.
SQL> Select LPAD (17000,10,*) from dual; Select LPAD (17000,10,*) from dual * ERROR at line 1: ORA-00936: missing expression SQL> SQL> Select LPAD (17000,10,'*') from dual; LPAD(17000 ---------- *****17000 SQL>
Asif Momen
http://momendba.blogspot.com -
A little help to write a SQL please? Maybe need some advanced features...
Hi all
I also write a SQL, code given in total and some rows in a table, can return the lines where a column is added to the total
These are operations, so I'm going to boil up to:
TranID, TranAmount
1, 100
2, 200
3, 250
4, 50
Suppose that I know that I must seek 2 transactions totaling 300.
Possible combinations are ID 1 + 2 or 3 + 4. In this case, it's a mistake that I can't find a single set of operations that meets the requirements of the number-and the sum - of
Suppose that I know that I must seek 3 transactions totalling 550.
Combination is ID 1 + 2 + 3
The difficulty for me here is the number of transactions were hunting will change, possibly without limits but it will be a factorial element in terms of number of combinations, imposing an upper limit would be appropriate.
I considered a solution in my understanding of SQL, I can take my lines, and (assuming I have apply a limit of 3 i.e. I can't watch for more than just a combination of 3 operations) cross to join them on their own to no tran ID is equal to any other ID tran I will then have a huge block of Cartesian joint operations. I can then use a where clause clause to choose combinations of lines having the correct sum. If I can use some kind of ID > otherID in my join, then I can do the Cartesian a triangle shape that hopefully would essentially prevent double rows of 1,2,3 and 1,3,2, 3,2,1 and 3,1,2 etc.
If I was looking for just 2 or 1 combinations, I would replace the tran with 0 amounts using a case when (because the number of times I'll join cross is fixed;) I don't want to get into dynamic sql execution)
Finally I would like to emphasize that I have do this in PL/SQL or possibly Java so I have the opportunity to introduce a custom so logic must be
I would be delighted to hear any other entry among the members of the sages and shriveled here as to how they can deal with this problem... Maybe oracle has some cool analytical features that I don't know who will help out here?
Thanks in advance guys n girls!CD / wrote:
Nocycle is really necessary?C.
Very good point cd. It was then that I was testing to try to get the answer, but in fact it is not necessary.
SQL> ed Wrote file afiedt.buf 1 with t as (select 1 as TranID, 100 as TranAmount from dual union all 2 select 2, 200 from dual union all 3 select 3, 250 from dual union all 4 select 4, 50 from dual) 5 -- end of test data 6 select distinct substr( trans 7 , decode( level, 1, 1, instr(trans,'+',1,level-1)+1) 8 , decode( instr(trans,'+',1,level), 0, length(trans), instr(trans,'+',1,level) - decode( level, 1, 0, instr(trans,'+',1,level-1))-1) 9 ) the_value 10 from (select trans 11 from ( 12 select ltrim(rtrim(comb.trans,'+'),'+') as trans, sum(case when instr(comb.trans,'+'||t.tranid||'+')>0 then tranamount else null end) as sum_tran 13 from (select sys_connect_by_path(tranid, '+')||'+' as trans 14 from t 15 connect by tranid > prior tranid) comb 16 ,t 17 group by comb.trans 18 ) 19 where sum_tran = 300) 20 connect by level < length(replace(translate(trans,'01234567890','00000000000'),'0')) + 2 21* order by 1 SQL> / THE_VALUE -------------------------------------------------------------------------------------------------------------------------------- 1 2 3 4 SQL>
-
Please guide for 11G: OCA, OCP or pl/sql sql, pl/sql, admin-1
Respected members
For better prospects working point of view which path should I choose for Oracle 11 G Certification?
OCA sql, pl/sql OCA, OCA admin-1
OR
SQL of the OCA, OCA pl/sql, OCP - advanced pl/sql
Please guide.
Concerning
Nileshbigdelboy is located on the two counts.
-You don't have to take the exams in this path in any formal succession. You can take the exam 146 before you have your 144 beta test results, but you will not be granted certification until scored 144 beta review (and you did).
-In addition, 146 review is based on the formation of 11g, but Advanced PL/SQL certification is not version-specific.
Kind regards
Brandye Barrington
Certification Forum Moderator
Manager certification program -
EMERGENCY required on forming the matrix of data using PL/SQL
Hi all
I'm new to this thread and need your emergency assistance in this regard.
I have a requirement for the construction of a matrix of 5000 X 5000 using PL/SQL. My original data tables have 5000 lines each and I need to make a correlation analysis using these data and need to store in a physical table, and not in memory. This feat feasible the simple use of PL/SQL? I understand that Oracle DB has a limit of 1000 columns (but not sure) and so I would like to know if there is a workaround for this kind of scenario. If not, what are the other alternative methods to achieve this feat? Do I need to use any 3rd party tools to do this? A quick response from experts is highly appreciated.
Thanking you in advance all the gurus.
Rgds
SAIDOUBLE WIRE!
Now that you have published in your question in the forum SQL and PL/SQL please mark this thread ANSWERED.
-
Hi Experts
I am trying to add SQL to a filter that has the attribute of the year (to display the data for the current year)
It's the next SQL, I entered this filter:
"Period of time". " An"=" SELECT DATENAME (YEAR, GETDATE().
However my report does not, after that this filter has been changed (with SQL)
Please notify
FranckHi Frank,.
Have you tried this using the filter:
"Period of time". " An"= Year (Current_Date)
Thank you
Hyder -
Hi guys,.
When creating procedures and functions in PL/SQL please can someone explain the difference by using key words IS and YOU.
Best regards
ShazYou can use either 'AS' or 'ARE' as you prefer.
See the PL/SQL language reference - http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/subprograms.htm#CHDBEJGF
There are a number of examples and uses these two. In here is a that uses IS
Example 8-3 Creating Nested Subprograms that Invoke Each Other DECLARE -- Declare proc1 (forward declaration): PROCEDURE proc1(number1 NUMBER); -- Declare and define proc 2: PROCEDURE proc2(number2 NUMBER) IS BEGIN proc1(number2); END;
But this one uses AS
Example 8-17 Invoking an IR Instance Methods -- OE creates a procedure that invokes change_job CREATE PROCEDURE reassign (p IN OUT NOCOPY hr.person_typ, new_job VARCHAR2) AS BEGIN p.change_job(new_job); -- executes with the privileges of oe END; / -- OE grants EXECUTE to HR on procedure reassign GRANT EXECUTE ON reassign to HR; -- HR passes a person_typ object to the procedure reassign DECLARE p1 person_typ; BEGIN p1 := person_typ(1004, 'June Washburn', 'SALES'); oe.reassign(p1, 'CLERK'); -- current user is oe, not hr END; /
-
PL SQL related (recursive) calculation
Please find below the tables
Table of EVENTS
event_id | gross_amount | transaction_id
1. 10. 1
2. 12. 5
TRANSACTIONS table
field | flow | credit | type | original_trx_id | last_updated
1. 0 | 0 | payment | null | JULY 25, 11
2. 0 | 2. Regulation | 1. JULY 26, 11
3. 0 | 1. Regulation | 1. 27 JULY 11
4. 3. 0 | Regulation | 1. JULY 28, 11
5. 0 | 0 | payment | null | 24 JULY 11
6. 0 | 3. Regulation | 5. JULY 25, 11
EXPECTED RESULT:
field | flow | credit | current_gross | current_net
2. 0 | 2. 10. 12
3. 0 | 1. 12. 13
4. 3. 0 | 12. 9
6. 0 | 3. 10. 13
Explanation
------------------
Transaction 1,2,3,4 fall into a game and transaction 5.6 fall into one game somehow. Each set of transactions can be controlled using Update column.
For the calculation, we do not take operations type "payment". The "payment" transaction is related to the event table. Hence you can find 'original_gorss_amount' for the calculation.
Measures
1.) find event table transaction for payment of the transaction table. (Ex: transaction_id = 1, also, that we can find original_gorss_amount = 10)
2.) take the entire transaction of "regulations" which has original_trx_id = 1
3.) stopped in function update time.
4.) apply the calculation
Hope you understood my question. I want to get the "RESULT WHEREAS" somehow using PL SQL (please no custom function)
I don't see a way to CONNECT BY here. Your help is very appreciate.
Please find below create table or insert.
----------------------------------------------------------
create table event
(event_id number (9),)
gross_amount number (9),
transaction_id number (9));
Insert the event values (1,10,1);
Insert the event values (2,10,5);
create table transaction
(field, number (9),)
flow number (9),
number (9) credit.
type varchar2 (50).
original_trx_id number (9),
last_updated DATE
);
Insert in transaction values (1,0,0, "payment", null, "2011-07-25');
Insert in transaction values (2,0,2, 'establishment', 1,'' 2011-07-26).
Insert in transaction values (3,0,1, 'establishment', 1,'' 2011-07-27).
Insert in transaction values (4,3,0, 'establishment', 1,'' 2011-07-28);
Insert in transaction values (5,0,0, "payment", null, "2011-07-24');
Insert in transaction values (6,0,3, 'regulation', 5, "2011-07-25');with t1 as ( select trx_id, debit, credit, connect_by_root trx_id root, rownum rn from transaction start with original_trx_id is null connect by original_trx_id = prior trx_id ), t2 as ( select trx_id, debit, credit, root, gross_amount - credit + debit + sum(credit - debit) over(partition by root order by rn) current_gross, gross_amount + sum(credit - debit) over(partition by root order by rn) current_net from t1, event where root = transaction_id ) select trx_id, debit, credit, current_gross, current_net from t2 where root != trx_id / TRX_ID DEBIT CREDIT CURRENT_GROSS CURRENT_NET ---------- ---------- ---------- ------------- ----------- 2 0 2 10 12 3 0 1 12 13 4 3 0 13 10 6 0 3 10 13 SQL>
SY.
-
SQL - select the data with the nearest past date
Hello
I have a requirement to retrieve data based on a closer effective_date in the past.
Here are examples of data
Data in the table
DESCRIPTION OF ARTICLE EFFECTIVE_DATE
---------------------------------------------------------------------------
018885237 24 OCTOBER 09 DVD + R 47 10 PK
DISC OF DVD + R 10 018885237 16 APRIL 10
040706113 FLASH PLAYER 24 OCTOBER 09
040706113 4 March 10 Micro USB 4 GB
040706113 13 January 10 Flash drive 4 GB
032140640 26 FEBRUARY 10 8 GB USB
032140640 24 OCTOBER 09 8 GB FLASH
The power required
DESCRIPTION OF ARTICLE EFFECTIVE_DATE
---------------------------------------------------------------------------
DISC OF DVD + R 10 018885237 16 APRIL 10
040706113 4 March 10 Micro USB 4 GB
032140640 26 FEBRUARY 10 8 GB USB
Can someone help me with the SQL please?
Concerning
HarshaSQL> --- generating sample data: SQL> with t as ( 2 select 018885237 item, to_date('24-OCT-09', 'dd-mon-yy') effective_date, 'DVD+R 47 10 PK' description from dual unio 3 select 018885237, to_date('16-APR-10', 'dd-mon-yy'), 'DVD+R 10 DISC' from dual union 4 select 040706113, to_date('24-OCT-09', 'dd-mon-yy'), 'FLASH DRIVE' from dual union 5 select 040706113, to_date('04-MAR-10', 'dd-mon-yy'), '4GB USB Micro' from dual union 6 select 040706113, to_date('13-JAN-10', 'dd-mon-yy'), 'Flash Driv 4GB' from dual union 7 select 032140640, to_date('26-FEB-10', 'dd-mon-yy'), '8GB USB' from dual union 8 select 032140640, to_date('24-OCT-09', 'dd-mon-yy'), '8GB FLASH' from dual 9 ) 10 -- 11 -- actual query 12 -- 13 select item 14 , effective_date 15 , description 16 from ( select item 17 , effective_date 18 , description 19 , row_number() over (partition by item order by effective_date desc) rn 20 from t 21 ) 22 where rn=1; ITEM EFFECTIVE DESCRIPTION ---------- --------- -------------- 18885237 16-APR-10 DVD+R 10 DISC 32140640 26-FEB-10 8GB USB 40706113 04-MAR-10 4GB USB Micro
-
Hi DBAs,
I am a part-time DBA and former DBA type configured SQL Prompt that shows something like this (User@SID) as sqlprompt
System@prod >
Now, if I need to stop and restart the database, this sqlprompt is suspended unless I have to press < ENTER > couple of times.
I want the default restore SQLPROMPT permanentely ' SQL > '
Please tell us how I can do it.
Thank you
-Samar-Configuration of the SQL in SQL command prompt * more could be done in the file login.sql or glogin.sql
This file is probably located at $ORACLE_HOME/sqlplus/admin/glogin.sql (even though it may be, if the old administrator has configured a different SQLPATH). There is an article on [configuration SQL * more | http://download.oracle.com/docs/cd/B28359_01/server.111/b31189/ch2.htm#i1132910] which presents different options here. It can also be configured in the user-specific login.sql file, but I guess that is not the case here since, presumably, the former administrator does not configure login.sql file your account.
In glogin.sql, looking for a line SET SQLPROMPT, which attaches to the SQL prompt. Eliminate that should restore the SQL > prompt.
Justin
-
Hello
We have just improved our test case Oracle APEX and now the ERR 7620 on certain applications and workspaces, but not all; can log in etc. fine application designer. With the help of 11g 2 with Oracle HTTP Server and Apex 5.0.2. Reason for upgrade has been issues with our new ADR configuration that we test; but this is not currently the live platform.
See you soon
David
Hello
You can run the following as SYS SQL please:
alter session set current_schema='APEX_050000'; select c.account_status, f.security_group_id from wwv_flows f, wwv_flow_companies c where f.security_group_id = c.provisioning_company_id and f.id = 214;
account_status should be ASSIGNED. If it is null then Oracle Support should be able to point to a Note that described for updating this status. ASSIGNED
Concerning
Patrick
-
Find duplicates of some merged ID
Extend the discussion I had recently by https://community.oracle.com/thread/3774735?sr=inbox , now I need to find duplicates in a table on which some data had been already merged.
Here ar a few test cases:
create table test_tbl ( IDM NUMBER(9) NOT NULL , ID_MERGE NUMBER(9) , CURRENT_ID NUMBER(9) , SNAME VARCHAR2(20) , FNAME VARCHAR2(20) , DBIRTH VARCHAR2(15) );
And the data are:
Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (125,NULL,125,'BOLOREY','JEANNE','11/05/1955'); Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (129,1000,1000,'BOLOREY','JEANNE','11/05/1955'); Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (127,1000,1000,'BOLOREY','JEANNE','11/05/1955'); Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (128,NULL,128,'BOLOREY','JEANNE','11/05/1955'); Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (126,1003,1003,'BOLLOREY','JEANNE','11/05/1955'); Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (123,1003,1003,'BOLLOREY','JEANNE','11/05/1955'); Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (131,1003,1003,'BOLLOREY','JEANNE','11/05/1955'); Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (150,NULL,150,'BOLLOREY','JEANNE','11/05/1955'); Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (133,NULL,133,'BOLLOREY','JEANNE','11/05/1955'); Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (153,NULL,153,'BALORE','GIANNE','11/05/1955'); Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (223,NULL,223,'ABOLLOREYY','JEANNE','11/05/1955'); Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (225,NULL,225,'FIABLE','MARINE','25/04/1963'); Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (226,1001,1001,'FIABLE','MARINE','25/04/1963'); Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (227,1001,1001,'FIABLE','MARINE','25/04/1963'); Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (228,1005,1005,'RINTET','MALIKA','07/08/1954'); Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (229,1005,1005,'RINTET','MALIKA','07/08/1954'); Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (240,NULL,240,'RINTET','MALIKA','07/08/1954'); Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (241,NULL,241,'RINTET','MALIKA','07/08/1954');
My goals are the same: use a temporary table to count in a second time duplicates; so, if I used the merged column:
CREATE TABLE test_dbl as SELECT m1.idm , m2.idm AS dup_key , COUNT (*) OVER (PARTITION BY m1.idm) AS dup_num FROM MEMBERS_TBL m1 JOIN MEMBERS_TBL m2 ON m1.idm != m2.idm AND m1.id_merge = m2.id_merge -- m1.idmerge = null or m2.idmerge = null AND m1.dbirth = m2.dbirth AND m1.fname = m2.fname AND m1.sname = m2.sname ORDER BY idm , dup_key ;
and when you count all the duplicates it gives me 9; But if If I insert m1.idmerge = null or m2.idmerge = null, I have no results
SELECT SUM(TOTAL_TYP_DBL) AS NBRE_DBL_STR_AV_NSS FROM ( SELECT TYPE_DOUBLONS, COUNT(TYPE_DOUBLONS) AS TOTAL_TYP_DBL FROM ( SELECT IDM, case count(*) when 1 then 'Doublons' -- IDM + 1 duplicate = 2 when 2 then 'Triplons' -- IDM + 2 duplicates = 3 when 3 then 'Quadruplons' when 4 then 'Quintuplons' when 5 then 'Sextuplons' when 6 then 'Septuplons' when 7 then 'Octuplons' when 8 then 'Nonuplons' when 9 then 'Décuplons' when 10 then 'Undécuplons' else 'Dodécuplons et plus' end as TYPE_DOUBLONS --count(*)+1 as dbl_cmp FROM TEST_DBL GROUP BY idm --where TYPE_DOUBLONS ='Dodécuplons et plus' ) GROUP BY TYPE_DOUBLONS ) ;
And it's not just because I have to take into account the new merged id (NULL or NOT)
Can someone please get a sense of how to write it in pl/sql please?
Thanks in advance
This message was edited by: 2986888 there are a few errors on the sample data.
Hello
2986888 wrote:
I tried to adapt your suggestion again and now I have this query that seems to work:
- CREATE TABLE test_dbl as
- SELECT m1.idm
- m2.idm AS dup_key
- COUNT AS dup_num (*) OVER (PARTITION BY m1.idm)
- MEMBERS_TBL M1
- JOIN MEMBERS_TBL m2 WE
- M1. IDM! = m2.idm
- AND ((DECODE (m1.id_merge, m2.id_merge, 0, 1) = 0) OR (DECODE (m1.id_merge, NULL, 0, 1) = 1) OR (DECODE (NULL, m2.id_merge, 0, 1) = 1))
- AND m1.dbirth = m2.dbirth
- AND m1.fname = m2.fname
- AND m1.sname = m2.sname
- ORDER BY idm
- dup_key
- ;
Wat is your point of view?
During the id_merge comparison, it looks like you want 2 rows to match when the id_merge, m1 = m2, id) merge OR when one is NULL, regardless of whether the other is NULL or neither. Is that what you want? (I don't see anything above about in this thread.)
If so, what you posted should work, but there are easier ways to do what you do online 09 above. For example:
SELECT m1.idm
m2.idm AS dup_key
COUNT AS dup_num (*) OVER (PARTITION BY m1.idm)
MEMBERS_TBL M1
JOIN MEMBERS_TBL m2 WE m1.idm! = m2.idm
AND LNNVL (m1.id_merge! = m2.id_merge)
AND m1.dbirth = m2.dbirth
AND m1.fname = m2.fname
AND m1.sname = m2.sname
ORDER BY idm
dup_key
;
If you don't want not calibrated LNNVL that it is difficult to understand, then you should lose DECODE for the same reason and make the comparison id_merge like this:
AND (m1.id_merge = m2.id_merge - not! = I posted)
OR m1.id_merge IS NULL
OR m2.id_merge IS NULL
)
[EDIT: I see now that the stew already suggested this in response #8, above.]
-
Hello world
I have a table called 'Before' like this:
CREATE TABLE 'BEFORE' ('ORIGIN' VARCHAR2 (5), VARCHAR2 (10) 'DESTINATION', 'RANG' VARCHAR2 (11), "TIME_MINUTE" NUMBER)
/
REM, INSERTING BEFORE
TOGETHER TO DEFINE
Insert in FRONT (ORIGIN, DESTINATION, RANK, TIME_MINUTE) values (' Paris', 'Strasbourg', 'Paris', 20' ");
Insert in FRONT (ORIGIN, DESTINATION, RANK, TIME_MINUTE) values ("Paris,"Strasbourg", 'La Villette', 150');
Insert in FRONT (ORIGIN, DESTINATION, RANK, TIME_MINUTE) values (' Paris', 'Strasbourg', 'Meaux' 30' ');
Insert in FRONT (ORIGIN, DESTINATION, RANK, TIME_MINUTE) values (' Paris', 'Strasbourg","Dormans", 10'");
Insert in FRONT (ORIGIN, DESTINATION, RANK, TIME_MINUTE) values (' Paris', 'Strasbourg', 'Dummy', 30' ");
Insert in FRONT (ORIGIN, DESTINATION, RANK, TIME_MINUTE) values (' Paris', 'Strasbourg', 'Strasbourg', 30' ");
Insert in FRONT (ORIGIN, DESTINATION, RANK, TIME_MINUTE) values (' Paris', 'Lyon', 'Paris', 15' ");
Insert in FRONT (ORIGIN, DESTINATION, RANK, TIME_MINUTE) values (' Paris', 'Lyon","Auxerre", 60'");
Insert in FRONT (ORIGIN, DESTINATION, RANK, TIME_MINUTE) values (' Paris', 'Lyon","METZ", 60'");
Insert in FRONT (ORIGIN, DESTINATION, RANK, TIME_MINUTE) values (' Paris', 'Lyon","Lyon", 30'");
and I would get the result in a table to be called 'After' like this:
CREATE TABLE 'AFTER' ('ORIGIN' VARCHAR2 (5), VARCHAR2 (10) 'DESTINATION', 'COUPLE_RANG' VARCHAR2 (24), "TIME_MINUTE" NUMBER)
/
REM in AFTER INSERTION
TOGETHER TO DEFINE
Insert in AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ('Paris', 'Strasbourg', 'Paris - La Villette', '170');
Insert in AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ('Paris', 'Strasbourg', 'Paris - Meaux', '50');
Insert AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ("Paris", "Strasbourg", "Paris - Dormans ', 30'");
Insert AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ("Paris", "Strasbourg", "Paris - Pantina, 50');
Insert in AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ('Paris', 'Strasbourg', 'Paris - Strasbourg', '50');
Insert in AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ("Paris,"Strasbourg", 'La Villette - Meaux',' 180'");
Insert AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ('Paris', 'Strasbourg', 'La Villette - Dormans, 160');
Insert AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ('Paris', 'Strasbourg', 'La Villette - Pantina, 180');
Insert in AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ("Paris,"Strasbourg", 'La Villette - Strasbourg',' 180'");
Insert AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ("Paris", "Strasbourg", "Meaux - Dormans ', 40'");
Insert AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ('Paris', 'Strasbourg', 'Meaux - Pantina, 60');
Insert in AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ('Paris', 'Strasbourg', 'Meaux - Strasbourg', '60');
Insert AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ("Paris", "Strasbourg", "Dormans - Pantina, 40');
Insert in AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ("Paris", "Strasbourg", 'Dormans - Strasbourg', '40');
Insert in AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ("Paris", "Strasbourg", 'Puppet - Strasbourg', '60');
Insert in AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ('Paris', 'Lyon', 'Paris - Auxerre', '75');
Insert in AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ('Paris', 'Lyon', 'Paris - METZ', '75');
Insert in AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ('Paris', 'Lyon', 'Paris - Lyon', '45');
Insert in AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ("Paris", "Lyon", 'Auxerre - METZ', '120');
Insert in AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ("Paris", "Lyon", 'Auxerre - Lyon', '90');
Insert in AFTER (ORIGIN, DESTINATION, COUPLE_RANG, TIME_MINUTE) values ("Paris", "Lyon", 'METZ - Lyon', '90');
In practice I would summarizing the time interval between each pair of rows for origin - destination as we see in table 'After'.
Is it possible to do in sql or pl/sql please?
Thank you for your help.
Frank perfect! Thank you very much.
-
I saw an article in 2009 about pi that cannot contain more CPU, see the following link:
I can't find any document that the current 5.1 vSphere still has this limitation or not.
If you know vSphere that 5.1 FT can support more than one processor for servers Exchange and SQL, please let me know.
Thank you
Doan Hien
The maximum rates are documented in http://www.vmware.com/pdf/vsphere5/r51/vsphere-51-configuration-maximums.pdf
André
Maybe you are looking for
-
After login to yahoo mail, facebook, flickr and possibly other sites, my sessions are ends prematurely. It wasn't a problem with the latest versions of Firefox. This isn't a problem with IE9, but I prefer to use Firefox. I run anti-malware, but which
-
Is there a way to display time as the 24-hour clock?
Is there a way to display the time as 24-hour phone ZTE Firefox's desktop clock?If this is not the case, there should be!
-
LabVIEW license diverted from 30 days trial license
The other day, I bought and installed a NI Developer suite and registered the product through the internet. When I run Labview to edit the screws I can see the following screen indicating that my Labview is allowed for ever. But after a few weeks, ar
-
Activation of Windows XP on a Dell Dimension 2400.
Spent 3 hours transferred to numbers different media trying to activate my installation. Due to a relocation after malware everything closed. Until now, 2 emails to the support of windows (with no response that included pictures of my product key)
-
The sony xperia Z3 has a front flash capacity?
Hello world Sorry if this question has already been answered, I was wondering just if the z3 was a flash screen for the front facing images as you get on the samsung/iphones? I couldn't find anything about it :/ Thanks in advance