Simple, but a difficult requirement for my SQL query.
Hey guys, quick n easy question:For an employee named ID, I need to return employees where there are TWO or MORE of employe_id hence the emp_code is the same.
So, if I have these test data:
create table test (emp_id number, emp_name varchar(40), emp_code varchar(10));
insert into test values (1, 'John', '555');
insert into test values (2, 'Andrew', '555');
insert into test values (3, 'Paul', '666');
insert into test values (4, 'Alex', '777');
insert into test values (5, 'Julian', '888');
insert into test values (6, 'Trent', '666');
SQL> select * from test;
EMP_ID EMP_NAME EMP_CODE
---------- ---------------------------------------- ----------
1 John 555
2 Andrew 555
3 Paul 666
4 Alex 777
5 Julian 888
6 Trent 666
6 rows selected.
Based on the condition, if emp_id 1 and 6 are provided, the query should return: EMP_ID EMP_NAME EMP_CODE
---------- ---------------------------------------- ----------
1 John 555
2 Andrew 555
3 Paul 666
6 Trent 666
There are two or more employees with the same emp_code.That's what I tried, but I think it is ugly and does not meet all of my requirements. If I want emp_id 1, then:
SQL> select * from test
2 where emp_id in ( select emp_id
3 from test test2
4 where test2.emp_code in ( select emp_code
5 from test t
6 where t.emp_id in (1)
7 )
8 );
EMP_ID EMP_NAME EMP_CODE
---------- ---------------------------------------- ----------
1 John 555
2 Andrew 555
This is correct, BUT if I run the query for emp_id = 4SQL> select * from test
2 where emp_id in ( select emp_id
3 from test test2
4 where test2.emp_code in ( select emp_code
5 from test t
6 where t.emp_id in (4)
7 )
8 );
EMP_ID EMP_NAME EMP_CODE
---------- ---------------------------------------- ----------
4 Alex 777
It is incorrect, because the requirement that "I need to send employees where there are TWO OR SEVERAL employee_id hence the emp_code is the same.".Is there another way I can get this to work, and also, without making so many internal queries?
Thank you
You can also try using an analytic function:
SQL> select emp_id, emp_name, emp_code
2 from
3 (
4 select emp_id, emp_name, emp_code
5 ,count(*) over (partition by emp_code) ct
6 from test
7 where emp_code in (select emp_code from test where emp_id in (1,4,6))
8 )
9 where ct > 1
10 ;
EMP_ID EMP_NAME EMP_CODE
-------------------- ---------------------------------------- ----------
2 Andrew 555
1 John 555
3 Paul 666
6 Trent 666
Tags: Database
Similar Questions
-
Hardware requirements for MS SQL Server for about 100 concurrent users
Can someone suggest the hardware configuration required for MS SQL Server for about 100 concurrent users?
Microsoft page suggests 2 GHz CPU and 4 GB of RAM, but it does not mention the number of users. Wonder how many users affects the performance of MS SQL.Your question of Windows 7 is more complex than what is generally answered in the Microsoft Answers forums. It is better suited for Windows Server on MSDN. Please post your question in the MSDN Windows Server forum.
http://social.msdn.Microsoft.com/forums/en-us/category/SQLServer/
-
Hi team,
I'm looking for a SQL query check data (ECC + CallVariable) due to a RESULT of SCRIPT EXECUTE when you ask an external VRU with a translation route to VRU with a 'run external Script '.
In my view, that the data are analyzed between the termination call detail + termination call Variable.
If you have already such a SQL query I would be very grateful to have.
Thanks and greetings
Nick
Omar,
respectfully, shorten the interval of a day might not be an option for a history report ;-)
I recommend to take a look at the following SQL query:
DECLARE @dateFrom DATETIME, @dateTo DATETIME
SET @dateFrom = ' 2014-01-24 00:00:00 '
SET @dateTo = ' 2014-01-25 00:00:00 '
SELECT
TCV. DateTime,
TCD. RecoveryKey,
TCD. RouterCallKeyDay,
TCD. RouterCallKey,
VME. EnterpriseName AS [ECVEnterpriseName],
TCV. ArrayIndex,
TCV. ECCValue
OF Termination_Call_Variable tcv
JOIN THE
(SELECT RouterCallKeyDay, RouterCallKey, RecoveryKey IN Termination_Call_Detail WHERE DateTime > @dateFrom AND DateTime)< @dateto)="">
THE tcv. TCDRecoveryKey = tcd. RecoveryKey
LEFT OUTER JOIN Expanded_Call_Variable VME ON tcv. ExpandedCallVariableID = VME. ExpandedCallVariableID
WHERE the tcv. DateTime > @dateFrom AND tcv. DateTime<>
With variables, you can set up your code (for example, you could write SET @dateFrom =? and let the calling application to fill in the DateTime for you).
In addition, join two large tables with all the lines, as you did (TCD - TCV) is never a good option.
Another aspect to consider: all the ECC is actually arrays (always), is not good to leave aside the index value (tcv. ArrayIndex).
G.
-
License required for "Automatic SQL Tuning Advisor"?
I noticed a lot of databases in my company show using a component called "Automatic SQL Tuning Advisor" or "Automatic maintenance - Setup SQL" in DBA_FEATURE_USAGE_STATISTICS.
Do we know if this component requires a License Pack Tuning or it could be one of the internal out-of-box/system uses that do not require a license?
Thank you!
I need a License Pack - Tuning
MOS Doc ID 276103.1
Best to check with your sales representative
-
Information required for generated SQL
Hello
I've done a few odi projects. In most of the RT operation when I check the operator code I saw that:
Insert into... .in 1 = 1;
or
Select... Of... where 1 = 1;
Does that mean 1 = 1?
There is no variable when or where condition.
Please years
Thank youHi Sarah Perreault,.
1 = 1 is a condition that is always true, and which is sometimes used in queries.
ODI uses in the generated code to valid questions with or without filters. Adding a filter will add a string: 'AND filter_condition.
Without filter:
select * from table where 1 = 1 ;
which is the same as select * from table;
Add a filter:
select * from table where 1 = 1 and col1 = 42 ;
Always-false conditions are also sometimes used by SQL developers. If you want to duplicate a table structure without duplicating the data:
create table2 as select * from table1 where 1 = 2;
Any line that is not returned, so some rows in the new table, but the structure is the same :).
It will be useful.
Kind regards
JeromeFr -
I installed the updates listed as prompted.
The message box confirms updates are successfully completed.
Then the updates icon comes back and invite updates again. To turn off the computer, the updates display icon are available to be installed appears on the close icon (with option disable ot without updating).
Is there a problem with the update program which does not update the registry somehow?
Hi PhilipHoney,
There is a known issue with the updates that you listed and a fix has been implemented. If you have not already the case, try to reinstall the update. This problem should be solved now.
-
Hi all
The application team uses under request and asked for recommendation for listening to this query.
The concern was
(1) how to avoid the query select sup as a query of subselects 3 is here which may degrade the performance of the query.
(2) in any case to avoid using the JOBBERDETAILS 5 times in NVL function.
SELECT "0". SM. SITE_ID AS "SD_SITE_NUMBER."
SA. ADDR_L1 AS "SD_SITE_ADDRESS."
SA. CITY_NAME AS "SD_SITE_CITY."
SA. STATE_AC AS "SD_SITE_STATE."
SUBSTR (SA. ZIP_CD, 0, 5) AS "SD_SITE_ZIP."
DECODE (LENGTH (TRIM (SA. ZIP_CD)), 5, '0000', SUBSTR (SA. ZIP_CD, 6, 4)) AS "SD_SITE_ZIP4."
SM. SITE_NAME AS "SD_NAME."
NVL ((SELECT SM. AM_SITE DOJ_NAME. B JOBBER_BASE WHERE B.SITE_ID = SM. (SITE_ID),' ') AS "SD_NAME2."
NVL (AM_SITE. JOBBERDETAILS (SA. (SITE_ID, 'OWNER_ADDRESS'),' ') AS "SD_MAILING_ADDRESS."
NVL (AM_SITE. JOBBERDETAILS (SA. (SITE_ID, 'OWNER_CITY'),' ') AS "SD_MAILING_CITY."
NVL (AM_SITE. JOBBERDETAILS (SA. (SITE_ID, 'OWNER_STATE'),' ') AS "SD_MAILING_STATE."
NVL (AM_SITE. JOBBERDETAILS (SA. (SITE_ID, 'OWNER_ZIP_CODE'),' ') AS "SD_MAILING_ZIP_CODE."
NVL (AM_SITE. JOBBERDETAILS (SA. (SITE_ID, 'OWNER_PHONE'), "0000000000") AS "SD_PHONE_NUMBER."
NVL ((SELECT ST. PHONE FROM AM_SITE. WHERE THE ST. SITE_TELEPHONE ST. SITE_ID = SM. SITE_ID AND SUPERIOR (ST. PHONE) = 'P'), "0000000000") AS "SITE_PHONE_NUMBER."
NVL ((SELECT B.J_SITE_ID FROM AM_SITE. B JOBBER_BASE WHERE B.SITE_ID = SM. SITE_ID AND AM_SITE. GET_COT (SM. (SITE_ID) = 'J'), "") AS "SD_JOBBER_NUMBER."
"1" AS "BANK_LEVEL."
"E' AS"AGENT. "
SM. DEFERRED_IND AS "DEFFERED_SETTLEMENT_INDICATOR."
SM. EXCESSIVE_CHAGK_IND AS "EXCESSIVE_CHARGEBACK_INDICATOR."
NVL (AM_SITE. GET_COT (SM. (SITE_ID),' ') AS "CHANNEL_OF_TRADE."
DECODE (AM_SITE. GET_COT (SM. ("" "" "SITE_ID),'d", '02', 'J', '11', ' C ', '23', "R", '21', 'N ' 21', ' Z ',' 21', 'NA') AS 'OUTLET_CODE '.
OF AM_SITE. SM, AM_SITE SITE_MSTR. SITE_ADDR SA
WHERE SM. SITE_ID = SA. SITE_ID AND SUPERIOR (SA. ADDR_TYPE) = 'P' AND SM. MOP_CD IS NOT NULL
Can someone please help me in setting this query.
Thanks in advanceFollower of the Oracle says:
Hi allThe application team uses under request and asked for recommendation for listening to this query.
The concern was(1) how to avoid the query select sup as a query of subselects 3 is here which may degrade the performance of the query.
Use outer joins instead of scalar subqueries. See for example the recent discussion of Tom Kyte: http://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:1594885400346999596
(2) in any case to avoid using the JOBBERDETAILS 5 times in NVL function.
You need to know what the function does, and replace it with a simple corresponding SQL expression. Most of the time these functions search the recursive SQL which can be very expensive. Although the functional separation is better in terms of encapsulation/maintainability ordinary SQL approach gives better performance if you have a result of great value.
Have you checked that above two points are key issues of this query? By work without the function calls and scalar subqueries, you can check if it performs much better. If this isn't the case, you will need to investigate on what is still the main culprit.
Kind regards
RandolfOracle related blog stuff:
http://Oracle-Randolf.blogspot.com/SQLTools ++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676 /.
http://sourceforge.NET/projects/SQLT-pp/ -
Need for the sql query to have several columns in a single coulumn
Hi all
I need create the query to have several columns in a single column with several lines.
Select a.customer_trx_id, a.previous_customer_trx_id
of ra_customer_trx_all one
where a.customer_trx_id =: customer_trx_id
Here, a.customer_trx_id and a.previous_customer_trx_id are in two columns. I need to put them in a single column.
Say: the foregoing is output
--------------------------------------------------------------------------------
a.customer_trx_id a.previous_customer_trx_id
--------------------------------------------------------------------------------
123456 87654
--------------------------------------------------------------------------------
Need for a single column
As
--------------------------------------------------------------------------------
123456
87654
--------------------------------------------------------------------------------
Please do the needful. Please note that it is not the UNION.
Thank you
AbdulHello
You want a way to confirm that what looks like two rows is really a line?
Here are three ways:
(1) count the lines:
WITH my_original_querry AS ( select a.customer_trx_id || CHR(13) || a.previous_customer_trx_id as id from ra_customer_trx_all a where a.customer_trx_id = 274881 ) SELECT COUNT (*) FROM my_original_query;
(2) in SQL * Plus, have SQL * more count them for you:
SET FEEDBACK 1 select a.customer_trx_id || CHR(13) || a.previous_customer_trx_id as id from ra_customer_trx_all a where a.customer_trx_id = 274881;
(3) implicitly count them with the ROWNUM Pseudo-column
select a.customer_trx_id || CHR(13) || a.previous_customer_trx_id as id , ROWNUM from ra_customer_trx_all a where a.customer_trx_id = 274881;
-
an idea for a SQL query?
I have a table with 2 columns. I want to choose the following lines:
(a) one of the 2 lines where 1st row: col1, col2 Row2 =: col2, col1
(b) all other lines where there is no equality constraint
Example:
Col1 Col2
-------------------------------------
ABC001 | BC987
BC987 | ABC001
CDE | PH
BC987 | XYZ
Result must be
(a) one of the 2 first lines because col1 value in 1st row is the same as col2 value in 2nd row; and col2 value in the 1st row is the same as the value of col1 in 2nd row.
(b) 2nd and 3rd rows (because they are unique lines)
Configuration data:
---------------
create table temptab (varchar2 (20) col1, col2 varchar2 (20))
insert into temptab values ("ABC001", "BC987")
insert into temptab values ('BC987', "ABC001")
insert into temptab values ("CDE", "PH")
insert into temptab values ('BC987', 'XYZ')
Thank youHello
It is an example of Request Top - N .
Assuming that col1 and col2 can be null:WITH got_rnum AS ( SELECT col1 , col2 , ROW_NUMBER () OVER ( PARTITION BY LEAST (col1, col2) , GREATEST (col1, col2) ORDER BY col1 ) AS rnum FROM temptab ) SELECT col1 , col2 FROM got_rnum WHERE rnum = 1 ;
If these columns can be NULL, it is messier, especially if there is no value (as "?") that you know does not occur in the table...
Thanks for posting the CREATE TABLE and INSERT!
-
You have no lines for the SQL query to select
Dear Sir.
I don't want to choose these lines in the second query, please guide me how to do.
Request-> 1
(SELECT ID_NO, ATTND_DATE FROM ATTND_REGISTER WHERE ATTND_DATE BETWEEN :FD AND :TD ORDER BY ID_NO, ATTND_DATE )AT
A query result.
ID_NO ATTND_DATE E1 FEBRUARY 1, 14 E1 FEBRUARY 2, 14 E1 3 FEBRUARY 14 E1 4 FEBRUARY 14 E1 FEBRUARY 5, 14 E1 FEBRUARY 6, 14 E1 FEBRUARY 7, 14 E1 FEBRUARY 8, 14 E1 FEBRUARY 9, 14 E1 10 FEBRUARY 14 E1 FEBRUARY 11, 14 E1 FEBRUARY 12, 14 E1 FEBRUARY 13, 14 E1 14 FEBRUARY 14 E1 15 FEBRUARY 14 E1 16 FEBRUARY 14 E1 17 FEBRUARY 14 E1 18 FEBRUARY 14 E1 19 FEBRUARY 14 E1 20 FEBRUARY 14 E4 FEBRUARY 1, 14 E4 FEBRUARY 2, 14 E4 3 FEBRUARY 14 E4 4 FEBRUARY 14 E4 FEBRUARY 5, 14 Request-> 2
: VALUE OF THE VARIABLE FD = 1 FEBRUARY 14
: VALUE OF THE VARIABLE TD = FEBRUARY 28, 14 '
SELECT A.ID_NO,B.DATES,A.EMP_NAME, A.DESG_NAME FROM ( SELECT ROWNUM - 1 + TO_DATE(:FD, 'DD/MM/RR') DATES FROM ALL_OBJECTS WHERE ROWNUM < TO_DATE(:TD, 'DD/MM/RR') - TO_DATE(:FD, 'DD/MM/RR') + 2 )B, ( SELECT ID_NO, INITCAP(FL_NAME) AS EMP_NAME, INITCAP(UBN.DESG_NAME(DESG_ID)) AS DESG_NAME FROM PERSONAL WHERE (STATUS = 'A') AND (COMPANY_CODE = :COMPANY_CODE)---COMPANY CODE=6 AND (ID_NO = :ID_NO OR :ID_NO IS NULL) )A ORDER BY A.ID_NO,B.DATES;
Solved
I changed in the second query with using the first query.
in Where Clause
WHERE B.DATES | A.ID_NO NOT IN (SELECT ATTND_DATE |) NBI ID_NO. ATTND_REGISTER
WHERE ATTND_DATE BETWEEN: FD AND: TD)
Thank you Allah (SWT).
-
UMI-7774 required for readers of nor?
I'm a movement control system design using 3 stepper motors (or Nema 23) and therefore 3 or P70360 readers. Is a umi-7774 required to connect to the controller 4 card pci motion-axis? (I'm confused as its description on the site nor said that it is necessary for the 3rd party readers BUT in discussions I've read a lot of people have used umi 7774 or readers)
Hello aks.
Yes, you will need to purchase and use our 7774 universal movement (UMI) Interface to connect the three engines of readers / motion controller card.
He could have confused because it does not explicitly say that it is necessary for the 3rd party readers, but not necessarily required for our readers. That said, the vast majority of customers use the UMI Board, because it eliminates the need for custom cables and makes it much easier to connect to several axes.
Here are some links that can provide more details and could be useful.
[1] NI Stepper Motion System selection guide
[2] of wiring for a movement with a Danaher drive system explained
-
R12 Payables: SQL query for the list of invoices and their status of Validation
Hi all
I am looking for a SQL query that gives me the list of all invoices of AP and their Validation status.
Thank you
AnilSelect invoice_id, invoice_num, invoice_amount, invoice_currency_code, AP_INVOICES_V approval_status_lookup_code;
Prasanna-
-
The search syntax of SQL query against the data type varchar2 preserving valid data.
Have a data model that we are not allowed to change and the column in question is a varchar2 (20). The column has at this stage no foreign key to the list of valid values. So, until we can get those who control the data model in order to make the adjustments we need for a SQL query that root out us bad data on the hours fixed.
Is what we expect to be good data below:
-Whole number, without floating point
-Length of 5 or less (greater than zero but less than 99999)
-Text "No_RP" can exist.
Request demo below works most of the time with the exception of 'or Column1 is null' is not contagious in the null record. I tried to change the logical terms around, but did not understand the correct layout still provide it. So help would be greatly appreciated it someone could put me straight on how to properly register a null value in the recordset that has been selected with other types of error for end users to correct their mistakes. Another thing, I suppose there could be a better approach syntactically to a call find all offender characters such as *, &, (and so on.)
WITH Sample_Data AS (SELECT '0' collar OF DOUBLE UNION ALL)
SELECT "2" collar OF DOUBLE UNION ALL
SELECT "99999" col OF DOUBLE UNION ALL
SELECT "100000" col OF DOUBLE UNION ALL
SELECT '1 a' collar OF DOUBLE UNION ALL
SELECT the "ABCD" OF DOUBLE UNION ALL pass
SELECT 'A1' collar OF DOUBLE UNION ALL
SELECT ' *' collar OF DOUBLE UNION ALL
SELECT "/" pass OF DOUBLE UNION ALL
SELECT '-' col OF DOUBLE UNION ALL
SELECT ' ' collar OF DOUBLE UNION ALL
SELECT "pass OF DOUBLE UNION ALL
4. SELECT 5 6' collar OF DOUBLE UNION ALL
SELECT "24.5" collar OF DOUBLE UNION ALL
SELECT '-3' collar OF DOUBLE UNION ALL.
SELECT 'A' collar OF DOUBLE UNION ALL
SELECT 'F' OF DOUBLE UNION ALL cervical
SELECT the 'Z' OF DOUBLE UNION ALL pass
SELECT the pass 'Bye' FROM DUAL UNION ALL
SELECT the "Hello World" OF DOUBLE UNION ALL pass
SELECT "=" col OF DOUBLE UNION ALL
SELECT "+" col OF DOUBLE UNION ALL
SELECT '_' pass OF DOUBLE UNION ALL
SELECT '-' col OF DOUBLE UNION ALL
SELECT ' (' col OF DOUBLE UNION ALL)
SELECT ')' collar OF DOUBLE UNION ALL
SELECT '&' collar OF DOUBLE UNION ALL
SELECT ' ^' collar OF DOUBLE UNION ALL
SELECT '%' collar OF DOUBLE UNION ALL
SELECT the pass of "$" OF DOUBLE UNION ALL
SELECT the pass ' # ' TO DOUBLE UNION ALL
SELECT ' @' collar OF DOUBLE UNION ALL
SELECT '!' collar OF DOUBLE UNION ALL
SELECT ' ~' collar OF DOUBLE UNION ALL
SELECT "' collar OF DOUBLE UNION ALL
SELECT '.' pass FROM DUAL
)
SELECT col from Sample_data
WHERE (translate (col, '_0123456789', '_') is not null
or length (col) > 5
col = 0 or
or col is null)
and (upper (col) <>'NO_RP');
One more thing, I also took the approach of the regular expression, but he could not understand. If anyone knows how to do with this approach, I would also appreciate learning this method as well. Below is a close because I had. Impossible to get a range to work as "between 0 and 100000", guessing because of the comparison of varchar2 and # even attempted using to_char and to_number.
Select to_number (column1) from the testsql where REGEXP_LIKE (column1, ' ^ [[: digit:]] + $') ORDER BY to_number (column1) CSA;
Thanks in advance for anyone to help.
NickHello
Thanks for posting the sample data in a useable form.
It would be useful that you also posted the accurate results you wanted from this data. You want the same results as those produced by the query you posted, except that nulls should be included? If so:SELECT col FROM sample_data WHERE CASE WHEN UPPER (col) = 'NO_RP' THEN 1 WHEN col IS NULL THEN -1 WHEN LTRIM (col, '0123456789') IS NOT NULL THEN -2 WHEN LENGTH (col) > 5 THEN -3 ELSE TO_NUMBER (col) END NOT BETWEEN 1 AND 99999 ;
The requirement that pass! = 0 gives that much more difficult. You could test easily for an integer from 1 to 5 digits, but then you must have a separate condition to make sure that the chain was not '0', '00', '000', ' 0000 'or ' 00000'.
(Unlike Solomon, I guess that do not want to choose no-0 numbers starting by 0, such as ' 007 'or ' 02138'.)Using regular expressions, you may lose a few keystrokes, but you also lose a lot of clarity:
SELECT col FROM sample_data WHERE REGEXP_LIKE ( col , '^0{1,5}$' ) OR NOT REGEXP_LIKE ( NVL ( UPPER (col) , 'BAD' ) , '^(([1-9][0-9]{0,4})|NO_RP)$' ) ;
Published by: Frank Kulash, December 13, 2010 21:50
Published by: Frank Kulash, December 13, 2010 22:11
Added regular expression solution -
Hi all
My version of Oracle: oracle 10G
I got a puzzle and very much if you could help me with the solution (I have it solved, but mine does not seek to be the best solution), if it is here, its got 2 parts:
Part 1:
Source data looks like:
AEK MANGO
AEK MANGO
AEK MANGO
AEK MANGO
AEK MANGO
AEK APPLE
AEK ORANGE
AEK LICHI
AEK LICHI
AEK LICHI
AEK LICHI
AEK LICHI
AEK LICHI
AEK LICHI
Abu MANGO
Abu MANGO
Abu APPLE
Abu APPLE
Abu APPLE
Abu ORANGE
Abu LICHI
Abu LICHI
Abu LICHI
Abu LICHI
Abu LICHI
Abu LICHI
Abu LICHI
Abu LICHI
Melanie MANGO
Melanie MANGO
Rémy APPLE
Rémy APPLE
Rémy APPLE
Rémy APPLE
Rémy APPLE
Rémy APPLE
Rémy ORANGE
Rémy ORANGE
Rémy ORANGE
Rémy ORANGE
Rémy ORANGE
Rémy ORANGE
Rémy ORANGE
Rémy ORANGE
Rémy ORANGE
Rémy LICHI
Rémy LICHI
Rémy LICHI
Rémy LICHI
Rémy LICHI
Shakti MANGO
Shakti MANGO
Shakti MANGO
Shakti MANGO
Shakti MANGO
Shakti MANGO
Shakti APPLE
Shakti APPLE
Shakti APPLE
Shakti APPLE
Shakti ORANGE
Shakti ORANGE
Shakti ORANGE
Shakti ORANGE
Shakti ORANGE
Shakti LICHI
power required by my sql query:
Orange mango apple lichi fname
1 7 5 1 AEK
Abu 3 8 2 1
Rémy 6 5 2 9
Shakti 4 1 6 5
-------------------------------------------
part B: is the opposite, my output above is my source and the result should be my source.
Please help me.
Concerning
Rahul
Published by: Mac_Freak_Rahul on January 26, 2012 06:20Hello
This makes for part 1:
Scott@my10g SQL>l 1 with t as ( 2 select 'abhi' c1, 'MANGO' c2 from dual 3 union all select 'abhi', 'MANGO' from dual 4 union all select 'abhi', 'MANGO' from dual 5 union all select 'abhi', 'MANGO' from dual 6 union all select 'abhi', 'MANGO' from dual 7 union all select 'abhi', 'APPLE' from dual 8 union all select 'abhi', 'ORANGE' from dual 9 union all select 'abhi', 'LICHI' from dual 10 union all select 'abhi', 'LICHI' from dual 11 union all select 'abhi', 'LICHI' from dual 12 union all select 'abhi', 'LICHI' from dual 13 union all select 'abhi', 'LICHI' from dual 14 union all select 'abhi', 'LICHI' from dual 15 union all select 'abhi', 'LICHI' from dual 16 union all select 'abu', 'MANGO' from dual 17 union all select 'abu', 'MANGO' from dual 18 union all select 'abu', 'APPLE' from dual 19 union all select 'abu', 'APPLE' from dual 20 union all select 'abu', 'APPLE' from dual 21 union all select 'abu', 'ORANGE' from dual 22 union all select 'abu', 'LICHI' from dual 23 union all select 'abu', 'LICHI' from dual 24 union all select 'abu', 'LICHI' from dual 25 union all select 'abu', 'LICHI' from dual 26 union all select 'abu', 'LICHI' from dual 27 union all select 'abu', 'LICHI' from dual 28 union all select 'abu', 'LICHI' from dual 29 union all select 'abu', 'LICHI' from dual 30 union all select 'anirudh', 'MANGO' from dual 31 union all select 'anirudh', 'MANGO' from dual 32 union all select 'anirudh', 'APPLE' from dual 33 union all select 'anirudh', 'APPLE' from dual 34 union all select 'anirudh', 'APPLE' from dual 35 union all select 'anirudh', 'APPLE' from dual 36 union all select 'anirudh', 'APPLE' from dual 37 union all select 'anirudh', 'APPLE' from dual 38 union all select 'anirudh', 'ORANGE' from dual 39 union all select 'anirudh', 'ORANGE' from dual 40 union all select 'anirudh', 'ORANGE' from dual 41 union all select 'anirudh', 'ORANGE' from dual 42 union all select 'anirudh', 'ORANGE' from dual 43 union all select 'anirudh', 'ORANGE' from dual 44 union all select 'anirudh', 'ORANGE' from dual 45 union all select 'anirudh', 'ORANGE' from dual 46 union all select 'anirudh', 'ORANGE' from dual 47 union all select 'anirudh', 'LICHI' from dual 48 union all select 'anirudh', 'LICHI' from dual 49 union all select 'anirudh', 'LICHI' from dual 50 union all select 'anirudh', 'LICHI' from dual 51 union all select 'anirudh', 'LICHI' from dual 52 union all select 'shakti', 'MANGO' from dual 53 union all select 'shakti', 'MANGO' from dual 54 union all select 'shakti', 'MANGO' from dual 55 union all select 'shakti', 'MANGO' from dual 56 union all select 'shakti', 'MANGO' from dual 57 union all select 'shakti', 'MANGO' from dual 58 union all select 'shakti', 'APPLE' from dual 59 union all select 'shakti', 'APPLE' from dual 60 union all select 'shakti', 'APPLE' from dual 61 union all select 'shakti', 'APPLE' from dual 62 union all select 'shakti', 'ORANGE' from dual 63 union all select 'shakti', 'ORANGE' from dual 64 union all select 'shakti', 'ORANGE' from dual 65 union all select 'shakti', 'ORANGE' from dual 66 union all select 'shakti', 'ORANGE' from dual 67 union all select 'shakti', 'LICHI' from dual 68 ) 69 select 70 c1 71 ,max(decode(rn,1,cnt,null)) l1 72 ,max(decode(rn,2,cnt,null)) l2 73 ,max(decode(rn,3,cnt,null)) l3 74 ,max(decode(rn,4,cnt,null)) l4 75 from ( 76 select c1,cnt,row_number() over (partition by c1 order by substr(c2,1,1)) rn 77 from ( 78 select c1,c2,count(*) cnt 79 from t 80 group by c1,c2 81 ) 82 ) 83 group by c1 84* order by c1 Scott@my10g SQL>/ C1 L1 L2 L3 L4 ------- ---------- ---------- ---------- ---------- abhi 1 7 5 1 abu 3 8 2 1 anirudh 6 5 2 9 shakti 4 1 6 5
I decided to not hardcode the four "fruits" inside the query so it would always works with anything else, as long as they do not share the initial letter.
---------
This should do the part 2:
Scott@my10g SQL>l 1 with t as ( 2 select 'abhi' n, 1 c1, 7 c2, 5 c3, 1 c4 from dual 3 union all select 'abu', 3, 8, 2, 1 from dual 4 union all select 'anirudh', 6, 5, 2, 9 from dual 5 union all select 'shakti', 4, 1, 6, 5 from dual 6 ) 7 select * 8 from ( 9 select t.n, 10 case 11 when m.column_value <= t.c1 then 'APPLE' 12 when m.column_value <= (t.c1+t.c2) then 'LICHI' 13 when m.column_value <= (t.c1+t.c2+t.c3) then 'MANGO' 14 else 'ORANGE' 15 end f 16 from t 17 ,table(cast(multiset(select level n from dual connect by level <= (t.c1+t.c2+t.c3+t.c4)) as sys.OdciNumberList)) m 18 ) 19* order by n, decode(f,'MANGO',1,'APPLE',2,'ORANGE',3,'LICHI',4) Scott@my10g SQL>/ N F ------- ------ abhi MANGO abhi MANGO abhi MANGO abhi MANGO abhi MANGO abhi APPLE abhi ORANGE abhi LICHI abhi LICHI abhi LICHI abhi LICHI abhi LICHI abhi LICHI abhi LICHI abu MANGO abu MANGO abu APPLE abu APPLE abu APPLE abu ORANGE abu LICHI abu LICHI abu LICHI abu LICHI abu LICHI abu LICHI abu LICHI abu LICHI anirudh MANGO anirudh MANGO anirudh APPLE anirudh APPLE anirudh APPLE anirudh APPLE anirudh APPLE anirudh APPLE anirudh ORANGE anirudh ORANGE anirudh ORANGE anirudh ORANGE anirudh ORANGE anirudh ORANGE anirudh ORANGE anirudh ORANGE anirudh ORANGE anirudh LICHI anirudh LICHI anirudh LICHI anirudh LICHI anirudh LICHI shakti MANGO shakti MANGO shakti MANGO shakti MANGO shakti MANGO shakti MANGO shakti APPLE shakti APPLE shakti APPLE shakti APPLE shakti ORANGE shakti ORANGE shakti ORANGE shakti ORANGE shakti ORANGE shakti LICHI 66 rows selected.
Published by: on January 26, 2012 Nicosa 15:51
-
Generate the Trace file to a sql query
Hi all
I want to generate a trace for a sql query file so that I can generate a .out file corresponding I need to check the performance of an application before using it.
Anyone can guide me please how to do this.
I know how do to generate a trace for a concurrent program, but right now, I want to track for a simple sql query.
Kind regards
AnkurHello
Agreed. but I thought that if OP do not have access to metalink then?In any case I not substitute me your answer.
Oops. Sorry I did not read the lines below.
You can turn simple trace for this particular session.
Oracle will generate trace files (.trc) for each session where the value of SQL_TRACE = TRUE and write them to the USER_DUMP_DEST destination. That you can use tkprof to read the generated trace file.Kind regards
TajPublished by: Mohammed Taj on July 14, 2009 10:11
Maybe you are looking for
-
Can I move my genealogy of Windows on a Mac?
Can I move my genealogy of Windows on a Mac? I don't want to lose the 30 years of research. Thank you Kathy Britton
-
After the update (40.0.2 @ 13.08.2015) just used Firefox open. The process is visible in the Task Manager, but does nothing. no window. JUST. NOTHING. It works only in safe mode or when ran as administrator. I tried other computers from home too. Sam
-
Canvio Aerocast Wireless HDD - looking for firmware update
Hello I have a 1.0.3 firmware on my hard drive wireless of Aerocast Canvio.I love this product, but have some stability issues, I saw that most Aerocast had a 1.0.4 firmware. No firmware is not available on the toshiba site.Anyone know where I can fi
-
Bluetooth in custody being extinguished
HelloI changed the power options on the wireless network and Bluetooth adapter so that they cannot be disabled - however, whenever the lappy goes to sleep and then I wake up it Bluetooth is disabled. Anyone know how to stop this case or what is turn
-
---------------------------Wzcsldr2.exe - Entry Point not found---------------------------The procedure entry point apsGetReady could not be found in the library of links dynamic wlanapi.dll.---------------------------Ok---------------------------