SQL query to retrieve a single record for each employee of the following table?
Hi all
Help me on the writing of SQL query to retrieve a single record for each employee of the following table? preferably a standard SQL.
CREATE TABLE xxc_contact)
empnum NUMBER,
alternatecontact VARCHAR2 (100),
relationship VARCHAR2 (10),
phtype VARCHAR2 (10),
Phone NUMBER
);
insert into xxc_contact values (123456, 'Rick Grimes', 'SP', 'Cell', 9999999999)
insert into xxc_contact values (123456, 'Rick Grimes', 'SP', 'Work', 8888888888)
insert into xxc_contact values (123457, 'Daryl Dixon', 'EN', 'Work', 7777777777)
insert into xxc_contact values (123457, 'Daryl Dixon', 'EN', 'Home', 3333333333)
insert into xxc_contact values (123456, 'Maggie Greene', 'CH', 'Cell', 9999999999)
insert into xxc_contact values (123456, 'Maggie Greene', 'CH', 'Home', 9999999999)
expected result:
EmpNum AlternateContact Relationship PhType Phone
123456 rick Grimes SP cell 9999999999
Daryl Dixon EN work 7777777777 123457
Home 123458 Maggie Greene CH 6666666666
Thanks in advance.
994122 wrote:
Thank you all, that I got a result
http://www.orafaq.com/Forum/m/620305/#msg_620305
By Lalit Kumar B...
Specifically, the two simple solutions provided were:
1 using the row_number, entitled Oracle ranking based on descending order of the inside telephone each empnum group. And finally selects the lines which has least rank (of least since that order is descending for phone).
SQL > column alternatecontact format A20;
SQL >
SQL > SELECT empnum, alternatecontact, relationship, phtype, phone
2 from (SELECT a.*, row_number() over r (PARTITION BY empnum ORDER BY phone / / DESC))
3 FROM xxc_contact one)
4. WHEN r = 1
/
EMPNUM ALTERNATECONTACT RELATIONSHIP PHTYPE PHONE
---------- -------------------- ---------- ---------- ----------
123456 rick Grimes SP cell 9999999999
Daryl Dixon EN work 7777777777 123457
Home 123458 Maggie Greene CH 6666666666
2. with the help of MAX, Oracle automatically assigns the maximum phone for all the rows in each group of empnum. And finally selects the rows with the maximum phone. Order by clause is omitted here intentionally. You can find out why.
SQL > SELECT empnum, alternatecontact, relationship, phtype, phone
2 (SELECT a.*, MAX (phone) over (PARTITION BY empnum) rn FROM xxc_contact one)
3 WHERE phone = rn
4.
EMPNUM ALTERNATECONTACT RELATIONSHIP PHTYPE PHONE
---------- -------------------- ---------- ---------- ----------
123456 rick Grimes SP cell 9999999999
Daryl Dixon EN work 7777777777 123457
Home 123458 Maggie Greene CH 6666666666
Kind regards
Lalit
Tags: Database
Similar Questions
-
Select a record for each Member of the Group
Hello
will have a table where in I'll take data for so many members of the group. I need to retrieve data for a particular group whose number of rows of data may be more in number (but I don't want only one row of data for each Member of the Group)
Here is the query to retrieve all rows of data
This query result is...select RI.RESOURCE_NAME,TR.MSISDN,TR.ADDRESS1_GOOGLE, TR.MSG_DATE_INFO, FROM TRACKING_REPORT TR, RESOURCE_INFO RI WHERE TR.MSISDN IN (SELECT MSISDN FROM RESOURCE_INFO WHERE GROUP_ID ='1' AND COM_ID=2 ) AND RI.MSISDN=TR.MSISDN order by MSG_DATE_INFO
>
DDD 12345 13 March 10 19:43:03
EEE 54321 Tamilnadu, India 13 March 10 19:39:48
DDD 12345 13 March 10 19:32:58
EEE 54321 Tamilnadu, India 13 March 10 19:30:07
DDD 12345 13 March 10 19:23:08
EEE 54321 Tamilnadu, India 13 March 10 19:20:14
FFF 98765 March 13 10 19:19:22
DDD 12345 13 March 10 19:13:01
EEE 54321 Tamilnadu, India 13 March 10 19:09:50
DDD 12345 13 March 10 19:02:56
EEE 54321 tn, ind March 13, 10 18:59:49
DDD 12345 13 March 10 18:53:08
EEE 54321 tn, ind March 13, 10 18:49:50
DDD 12345 13 March 10 18:42:56
EEE 54321 tn, ind March 13, 10 18:39:50
DDD 12345 13 March 10 18:33
EEE 54321 tn, ind March 13, 10 18:29:50
DDD 12345 13 March 10 18:22:54
EEE 54321 tn, ind March 13, 10 18:19:50
DDD 12345 13 March 10 18:12:56
EEE 54321 tn, ind March 13, 10 18:09:50
DDD 12345 13 March 10 18:02:54
EEE 54321 tn, ind March 13, 10 18:00:02
FFF 98765 Tamilnadu, India March 13, 10 17:59:26
FFF 98765 Tamilnadu, India March 13, 10 17:54:26
DDD 12345 13 March 10 17:52:56
EEE 54321 tn, ind March 13, 10 17:49:50
FFF 98765 Tamilnadu, India March 13, 10 17:49:25
FFF 98765 Tamilnadu, India March 13, 10 17:44:26
DDD 12345 13 March 10 17:42:56
>
This output, I only want a new album for each member(ddd,eee,fff). That is to say
>
DDD 12345 13 March 10 19:43:03
EEE 54321 Tamilnadu, India 13 March 10 19:39:48
FFF 98765 March 13 10 19:19:22
>
How to change the query to do this...?Ok. I looked more carefully at your sample and it looks like you are looking for:
SELECT RI.RESOURCE_NAME, TR.MSISDN, MAX(TR.ADDRESS1_GOOGLE) KEEP(DENSE_RANK LAST ORDER BY TR.MSG_DATE_INFO), MAX(TR.MSG_DATE_INFO) FROM TRACKING_REPORT TR, RESOURCE_INFO RI WHERE TR.MSISDN IN ( SELECT MSISDN FROM RESOURCE_INFO WHERE GROUP_ID ='1' AND COM_ID=2 ) AND RI.MSISDN = TR.MSISDN GROUP BY RI.RESOURCE_NAME, TR.MSISDN /
SY.
-
Hi all
I have a requirement where I need to get all the records, for each record in double, I need to get a single column with null or 0.
create table a1
(
Identification number,
VARCHAR2 (100), the point
part varchar2 (100));
Insert into a1
values (1, 'ABC', 'A1');
Insert into a1
values (2, 'DEF', 'A2');
TABLE A
PART ITEM ID
1 ABC A1
1 ABC A1
1 ABC A1
DEF 2 A2
DEF 2 A2
3 DEF A2
O/P
PART ITEM ID
1 ABC A1
1 ABC 0
1 ABC 0
DEF 2 A2
2 DEF 0
3 DEF 0
Thanks in advance.
Thanks for your help FrankKalush...
This one will work.
WITH got_r_num AS
(
SELECT NVL (a1.id, a1.id) as id
NVL (a1.item, a1.item) AS element
NVL (a1.part, a1.part) IN the framework
a1.id AS a_id
ROW_NUMBER () OVER (PARTITION BY a1.id
ORDER BY NULL
) AS r_num
BY the a1
)
SELECT id
element
CASE
WHEN a_id IS NOT NULL
AND r_num = 1
THEN part
ELSE ' 0'
END in the framework
OF got_r_num
;
-
I need a query that selects the amount of records for each day of a table.
I need a query that selects the amount of records for each day of a table.
For example, the result would be:
1 14 date
Date 2-3
etc.
Any ideas?Sort:
SELECT count ([IDCommentaire]), convert (varchar, dateAdded, 112)
OF COMMENTSgroup by convert (varchar, dateAdded, 112)
-
Using a single server for Multiple Instances of the APEX HTTP
Our company DBA asked if it would be possible to outsource the server part of HTTP of APEX from DB servers. In other words, it would be highly preferable as DB servers * only * start the Oracle database software.
We know that we can install the HTTP server on another box, but in thinking how to that, we were wondering if it's really necessary to create a separate HTTP Server installation for each instance of the APEX. What we would really like to do, is have a HTTP server for all our our boxes of Dev and several (but not one) for each of our superior environments; implementation stage, qa, prod, etc..
Right now, each instance has a file single dads.conf on every box of DB. So, if we we to try to consolidate, we need some way to incorporate several dads files and associate each correct instance.
Someone has already done this or (preferably) to have some examples?
Thank you
-Joe
The second page on the link provided José begins immediately with the "Configuration of several databases".
Yes, you can consolidate permanently. It is a common practice that was also available with Apache/mod_plsql, OSH and now with APEX earphone 2.
Thank you
Jorge
-
Where is 'Create a separate record for each volume' past? in VMware-converter - 4.0.1 - 161434 (independent). Option is not more than 4 converter?
Hello.
When you get to the third tab called "View/Edit Options", choose the Edit option for 'Data to copy.' Then choose the option advanced at the end of the menu "data copy type" and then use the options on the page layout tab target to assign separate discs.
Good luck!
-
Select the last value for each day of the table
Hello!
I have a table that contains several measures for each day. I need two queries on this table, and I'm not sure how to write them.
The table stores the rows (sample data)
Explanation of the data in the sample table:*DateCol1 Value Database* 27.09.2009 12:00:00 100 DB1 27.09.2009 20:00:00 150 DB1 27.09.2009 12:00:00 1000 DB2 27.09.2009 20:00:00 1100 DB2 28.09.2009 12:00:00 200 DB1 28.09.2009 20:00:00 220 DB1 28.09.2009 12:00:00 1500 DB2 28.09.2009 20:00:00 2000 DB2
We measure the size of the data files belonging to each database to one or more times a day. The value column indicates the size of the files of database for each database at some point (date in DateCol1 European model).
What I need:
Query 1:
The query must return to the last action for each day and the database. Like this:
Query 2:*DateCol1 Value Database* 27.09.2009 150 DB1 27.09.2009 1100 DB2 28.09.2009 220 DB1 28.09.2009 2000 DB2
The query should return the average measurement for each day and the database. Like this:
Could someone please help me to write these two queries?*DateCol1 Value Database* 27.09.2009 125 DB1 27.09.2009 1050 DB2 28.09.2009 210 DB1 28.09.2009 1750 DB2
Please let me know if you need further information.
Published by: user7066552 on September 29, 2009 10:17
Published by: user7066552 on September 29, 2009 10:17Why two queries when it suffice ;)
SQL> select dt 2 , db 3 , val 4 , avg_val 5 from ( 6 select dt 7 , val 8 , db 9 , row_number () over (partition by db, trunc (dt) 10 order by dt desc 11 ) rn 12 , avg (val) over (partition by db, trunc (dt)) avg_val 13 from test) 14 where rn = 1 15 order by dt 16 / DT DB VAL AVG_VAL --------- ----- ---------- ---------- 27-SEP-09 DB2 1100 1050 27-SEP-09 DB1 150 125 28-SEP-09 DB2 2000 1750 28-SEP-09 DB1 220 210
-
Adding column which gives the serial number for each line in the Bulletin Board
I use the update version 2 Jdev 11 g.
I'm the filling of all employees from the emp table ADF table.
My requirement is to add a column more as the first column and header line which displays the serial number for each serial number of row.the is not available in the table emp in database .i want to generate it dynamically when the data are filled in to ADF table.i don't want not to use the method to get the SQL query rownum. I want to get custom code (in the Managed Bean) or set all of the properties in the subject entity or any other object.
Published by: sj0609 on September 8, 2009 09:43Hello
Give an id to the table (say 'currRow') varStatus property. Add a column to the table (for example with a text output), then set it to the value of the output text #{currRow.index}.
Arun-
-
Original title: Task Scheduler
When I open Task Scheduler and click on MSE for planning, I get the following warning.
General Initializatin page failed,
The specific error is:
0 x 80070534: no mapping between account names and security IDS was done. Year error has occurred trying to retrieve task account informaiton. You can continue to edit the subject of the task, but will not be able to change task account information.
I then press the ok button and it goes to the task, schedule, and the settings box.
When I check in scheduled tasks, to see if they ran as planned, the last run time column NEVER said, and the status column indicates
COULD NOT START.
In the morning, I always get this error message:
A task could not run...
Do you know what I'm doing wrong? Can it be fixed?
Thank you Tim
Is there a password the user account in which the task is scheduled? You cannot schedule a task to run under a user without password account.
You can also take a look at advanced > view the log window scheduled tasks.
-
I want a single Inbox for each account. i.e. explain "Hotmail" and the folder "Inbox" and "Cybernet1" and the "Inbox" folder, I have to search for each folder to show messages in that folder now and I prefer just to check the Inbox for each account. Jim
In response to Zenos. See the attached picture. As you can see, I have two accounts in the local folders. I want to see the e-mail files in an Inbox under each account shown separately. See my answer to the gnospen for more information. Jim
-
Creation of 5 rows in table B for each row in the table has
For each row in the table, I want 5 rows to be created in the table b. table B should look likecreate table A (col1 number, col2 varchar2(20) ) / create table B (col1 number, col2 varchar2(20) ) / insert into A values (1,'Jane'); insert into A values (2,'Kate'); insert into A values (3,'Stomp'); SQL> select * from a; COL1 COL2 ---------- ----------------- 1 Jane 2 Kate 3 Stomp
How can I do this?COL1 COL2 ---------- ----------------- 1 Jane 2 Jane 3 Jane 4 Jane 5 Jane 6 Kate 7 Kate 8 Kate 9 Kate 10 Kate 11 Stomp 12 Stomp 13 Stomp 14 Stomp 15 Stomp
Hello
A way
insert into b select rownum*5 , col2 from a union all select rownum*5+1, col2 from a union all select rownum*5+2, col2 from a union all select rownum*5+3, col2 from a union all select rownum*5+4, col2 from a
Concerning
Anurag -
(For each) components in the OSB
I try to use component "For-Each" to perform a loop on the message to bulk out bulk and publish individual messages of the loop. However the loop does not run several times. It passes through the only once for each component. The key message is ';' separated from text messages.
There are about 4-5 different parameters to be set for the component. as a County, index, param, and xpath.
What best values to put in it so that the component gives the desired effect?
Thanks in advance.You try to say I'm going to use a component of the NEWSPAPER inside the component for EACH?
N ° it is a control sample if the loop is getting executed as required. You can completely ignore the alert/Log and place your logic. With sample data that you have posted, I have confirmation code posted earlier worked on my local machine. You may need to change depending on your use case.
But with my specified parameters for EACH component is not executed at least once.
The first glance, it seems that you XPath: v_XML. BUlkMessage.Transaction (v_XML here are the above XML code) has something to do with your problem. You should return table of elements that confirm specific condition. With the help of .//transaction is a way to query all the
with in the specific variable. Thank you
Maury -
How can I make a cell formula will apply for the entire column? For example D2 appears B2 - C2. How can I copy this formula for each cell in the column?
If you want the formula is the same (B2 - C2) in the cell of each column you must change it as ($B$ - 2$ C$ 2). Then copy it, select the whole column and paste.
-
Hello
I was wondering if I could get some information and opinions on the use of an array of type defined clusters to store configuration data. I am creating a program to test several EHR and wanted to have a control of type defined for each HAD with the information needed to create the DAQmx tasks for all signals for it must HAVE. I am eager to do so that the data are encoded in hard and not in a file that the user might spoil.
Controls of type def are then put into a Subvi who chooses as appropriate, one based on the enumeration of Type DUT connected to a case structure.
I have problems with the control of the defined type. I see issues when you try to save a configuration unique to each element of the array in the array of clusters. Somehow, it worked at first, but now by clicking on "Operations on the data--> default font of the current value ' on individual elements of the cluster or the entire cluster (array element) does not save data when I re - open the command def. What I am doing wrong? I'm trying to do something with the berries of the clusters that I shouldn't do?
I enclose one of the defined reference type controls. I tried to change it bare to see if that helped, but no luck.
To reproduce, change the resource string for the element 0 of the array and do the new value by default. Then close the def of type, and then reopen it. The old value is always present in this element. The VI is saved in LabVIEW 2012.
The values of a typedef are not proprigated to the instances of the control. They get if created WHEN data values have changed. They will be not updated with the changes to come. You must create a VI specifically to hardcode your values or to implement a file based initialization. The base file would be much better and more flexible. If you don't want users to change the data simply encryption. There is a wedding blowfish library that you can download.
-
My system features, i7 thinkpad w540, 16 GB of ram and a 256 GB ssd. Using MSE as av with AMBM pro
whenever I start my system, win 7 x 64, I get the following error in the event viewer:
Custom dynamic link libraries are loaded for each application. The system administrator should review the list of libraries to ensure that they are linked to trusted applications.
any help with this error?
Atul
Description: NVIDIA shim dll initialization
- Product: Shim NVIDIA D3D drivers
Company: NVIDIA Corporationhttp://systemexplorer.net/file-database/file/nvinit-dll/33069751I would not be concerned by this driver.
- Product: Shim NVIDIA D3D drivers
Maybe you are looking for
-
Pages: Sounds/Photos as reference text?
Can I use a photo (or a melody?) as a reference in the Pages? I'm writing a story in Pages and music (its not text) and pictures to be endnotes. Is this possible please? I use a MacBook Air. My opus system is OS X Yosemite 10.10.5. Thank you John M
-
can someone please tell me if a XEON 3050 can be mounted on a HP DC7600 sff. BIOS has been updated with the latest firmware (Bios v 1.60). Thank you
-
trying to put in place the 2nd user account and cannot get a password
you have a user account, but cannot get a password
-
as page gets so full of mundane things, I need to simplify and remove what I'm not interested in it, just delete banal stuuf ASAP.
-
Hello, this is my first post. Didn't know a better place to ask then here. If you would be grateful if someone could help me with this error. After a new installation of Windows he made their appearance. Have tried to use the "Diagnostic tool for Win