Selecting the second result for each client...
Hi,
I have a table containing all the contacts we had with our clients.
We consider a file an active file from the moment there have been 2 contacts for that client.
Today somebody asked me "can you tell me how many new clients with an active file we have this year"
So what I actualy want to do now, is make a view containing the DATE of the SECOND CONTACT for each CLIENT_ID.
the table looks like this:
CONTACT_ID
CLIENT_ID
DATE
CONTACT_FORM (doesn't matter in this story)
REMARKS (doesn't matter in this story)
Can somebody assist me with this please?
Thanks in advance for your replies.
L
edit I do know how to make a view, that's not the problem :) in this case only the select query to make it is the problem.
edit 2 I made a little example
If I start with this table data:
CLIENT_ID || DATE .... other columns here...
436 || 01-02-2011
328 || 05-04-2011
319 || 13-01-2011
220 || 03-09-2011
319 || 17-12-2011
220 || 25-11-2011
436 || 01-04-2011
436 || 01-04-2011than the view would have to make me end up with:
CLIENT_ID || DATE_OF_SECOND_CONTACT
436 || 01-04-2011
220 || 25-11-2011
319 || 17-12-2011(working with version 11.2.0.1.0)
Edited by: 901981 on 13-dec-2011 2:16
I hope this helps:
with t as
select 436 client_id, to_date('01-02-2011','DD-MM-YYYY') d from dual union all
select 328 client_id, to_date('05-04-2011','DD-MM-YYYY') d from dual union all
select 319 client_id, to_date('13-01-2011','DD-MM-YYYY') d from dual union all
select 220 client_id, to_date('03-09-2011','DD-MM-YYYY') d from dual union all
select 319 client_id, to_date('17-12-2011','DD-MM-YYYY') d from dual union all
select 220 client_id, to_date('25-11-2011','DD-MM-YYYY') d from dual union all
select 436 client_id, to_date('01-04-2011','DD-MM-YYYY') d from dual union all
select 436 client_id, to_date('01-04-2011','DD-MM-YYYY') d from dual
select client_id,
to_char(d,'DD-MM-YYYY') d
from
select client_id,
d,
row_number() over (partition by client_id order by d) rn
from t
where rn=2; Edited by: hm on 13.12.2011 02:17
please try out this to see how it works:
with t as
select 436 client_id, to_date('01-02-2011','DD-MM-YYYY') d from dual union all
select 328 client_id, to_date('05-04-2011','DD-MM-YYYY') d from dual union all
select 319 client_id, to_date('13-01-2011','DD-MM-YYYY') d from dual union all
select 220 client_id, to_date('03-09-2011','DD-MM-YYYY') d from dual union all
select 319 client_id, to_date('17-12-2011','DD-MM-YYYY') d from dual union all
select 220 client_id, to_date('25-11-2011','DD-MM-YYYY') d from dual union all
select 436 client_id, to_date('01-04-2011','DD-MM-YYYY') d from dual union all
select 436 client_id, to_date('01-04-2011','DD-MM-YYYY') d from dual
select client_id,
d,
row_number() over (partition by client_id order by d) rn
from t;(By the way: in my opinion it is not a good idea to choose a keyword "DATE" as a column name. That the reason why I choose "d" in my example.)
Similar Messages
-
How to select the first row for each pair of values ?
Hi guys, am hoping someone can help me here.
If I have 4 tables - Building, Dept, Emp, Text
B D E T
A 1 Z blah1
A 1 X blah2
A 1 W blah3
A 2 V blah4
A 2 G blah5
A 2 H blah6
B 1 K blah7
B 1 L blah8
B 2 E blah9
B 2 F blah0
I need a query that will bring back the first bit of text for each pair of building and dept records.
So the results I would get would be
A 1 blah1
A 2 blah4
B 1 blah7
B 2 blah9
blah2 wouldnt be returned, because we have already had a record from the Building A, dept 1 pairing.
Likewise we wouldnt get blah5 because we have already had a record from the Building A, dept 2 pairing.
Can this be done in 1 query??
Thanks all.
Message was edited by:
Scott Hillierhere you go
SQL> drop table t;
Table dropped.
SQL> create table t(B char(1), D integer, E char(1), T varchar2(5));
Table created.
SQL> insert into t values('A', 1, 'Z', 'blah1');
1 row created.
SQL> insert into t values('A', 1, 'X', 'blah2');
1 row created.
SQL> insert into t values('A', 1, 'W', 'blah3');
1 row created.
SQL> insert into t values('A', 2, 'V', 'blah4');
1 row created.
SQL> insert into t values('A', 2, 'G', 'blah5');
1 row created.
SQL> insert into t values('A', 2, 'H', 'blah6');
1 row created.
SQL> insert into t values('B', 1, 'K', 'blah7');
1 row created.
SQL> insert into t values('B', 1, 'L', 'blah8');
1 row created.
SQL> insert into t values('B', 2, 'E', 'blah9');
1 row created.
SQL> insert into t values('B', 2, 'F', 'blah0');
1 row created.
SQL> select b,d,t
2 from (
3 select row_number() over(partition by b, d order by b,d) rno,b,d,t
4 from t)
5 where rno = 1;
B D T
A 1 blah1
A 2 blah4
B 1 blah7
B 2 blah9karthick
http://karthickarp.blogspot.com/ -
Hello,
I have a strange issue on my Windows 8.1 machine. The icon for for an executable file on the network shows blank, if I select the second icon from the library. (File->Properties->Change Icon and select the second icon - This file has two icons)
If I re-create the IconCache.db, then it is showing correctly. But I do not want to do this every time.
Regards
MattehwIt indicates your Icon Cache is corrupted and you need to rebuild it.
Open the command prompt window, type each of the following and after every command, hit the Enter button:
cd /d %userprofile%\AppData\Local
attrib –h IconCache.db
del IconCache.db
start explorer
S.Sengupta, Windows Entertainment and Connected Home MVP -
Getting the first row for each group
Hi Everyone,
I have a query which returns a number of rows, all of which are valid. What I need to do is to get the first row for each group and work with those records.
For example ...
client flight startairport destairport stops
A fl123 LGW BKK 2
A fl124 LHR BKK 5
B fl432 LGW XYZ 7
B fl432 MAN ABC 8
.... etc.
I would need to return one row for Client A and one row for Client B (etc.) but find that I can't use the MIN function because it would return the MIN value for each column (i.e. mix up the rows). I also can use the rownum=1 because this would only return one row rather than one row per group (i.e. per client).
I have been investigating and most postings seem to say that it needs a second query to look up the first row for each grouping. This is a solution which would not really be practical because my query is already quite complex and incorporating duplicate subqueries would just make the whole thing much to cumbersome.
So what I really new is a "MIN by group" or a "TOP by group" or a "ROWNUM=1 by group" function.
Can anyone help me with this? I'm sure that there must be a command to handle this.
Regards and any thanks,
Alan Searle
Cologne, GermanySomething like this:
select *
from (
select table1.*
row_number() over (partition by col1, col2 order by col3, col4) rn
from table1
where rn = 1In the "partition by" clause you place what you normally would "group by".
In the "order by" clause you define which will have row_number = 1.
Edit:
PS. The [url http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions004.htm#i81407]docs have more examples on using analytical functions ;-)
Edited by: Kim Berg Hansen on Sep 16, 2011 10:46 AM -
How to use the second display for installation OS in my vertical lines iMac
My 17" iMac display is full of vertical lines, it is unuseable. Does anyone know how to use the second display for Mac OS X or disable the first display for installation Mac OS x ?
Go to: *System Preferences > Displays* and select the Arrangement tab, then relocate your Menu bar by dragging it to the other display.
Unfortunately there is no Hardware or Software switch to turn off the iMac's Internal Display. -
How to define a separate virtual host for each client in SICF
Hello,
We have an ERP system with multiple clients running on it. The WebDynpro ABAP applications once developed are available on all clients, as standard. However, this is not our desired behavior. We want:
1. The WebDynpro ABAP applications should be managed separately in SICF depending on the client
2. The URL for accessing the WebDynpro application should have a own host name for each client. e.g.
A WebDynpro application on client 100 should be accessed by http://host1:5000/sap/bc/... and the same application on client 200 should be accessed by http://host2:5000/sap/bc/...
After a while researching I find out that creating a virtual host for each client in SICF would be a possible solution to fulfill the above mentioned requirments:
1. Set the profile parameter is/HTTP/virt_host_* with corresponding host name and port number
2. Create a new virtual host in SICF assigning the profile paramter to it
3. Assign a client to this virtual host
My question is how to specify a client to a virtual host? I didn't find any possibilities in SICF!
Anyone can help me? Thanks a lot in advance!
Best Regards
Di LiHi Srikishan,
thanks for your reply. Your suggested way is certainly a potential, and also my preferred option for solving the multiple-client-capable URL access to WebDynpro / BSP applications.
However, for some reasons, based on the customer requirements, the client should not be visible in the URL. The URL for accessing the WebDynpro / BSP applications on different client should have different host name, as if they are different companies. Besides that, we want to manage each WebDynpro / BSP application on different clients in SICF separately.
Therefore, at least on my opinion, we need to introduce a virtual host for each client in SICF. But how do I make it happen?
Regards
Di -
How to define a separate virtual host for each client in ICF for WebDynpro
Hi,
We have an ERP system with multiple clients running on it. The WebDynpro ABAP applications once developed are available on all clients, as standard. However, this is not our desired behavior. We want:
1. The WebDynpro ABAP applications should be managed separately in SICF depending on the client
2. The URL for accessing the WebDynpro application should have a own host name for each client. e.g.
A WebDynpro application on client 100 should be accessed by http://host1:5000/sap/bc/... and the same application on client 200 should be accessed by http://host2:5000/sap/bc/...
After a while researching I find out that creating a virtual host for each client in SICF would be a possible solution to fulfill the above mentioned requirments:
1. Set the profile parameter is/HTTP/virt_host_* with corresponding host name and port number
2. Create a new virtual host in SICF assigning the profile paramter to it
3. Assign a client to this virtual host
My question is how to specify a client to a virtual host? I didn't find any possibilities in SICF!
Anyone can help me? Thanks a lot in advance!
Best Regards
Di LiHi Srikishan,
thanks for your reply. Your suggested way is certainly a potential, and also my preferred option for solving the multiple-client-capable URL access to WebDynpro / BSP applications.
However, for some reasons, based on the customer requirements, the client should not be visible in the URL. The URL for accessing the WebDynpro / BSP applications on different client should have different host name, as if they are different companies. Besides that, we want to manage each WebDynpro / BSP application on different clients in SICF separately.
Therefore, at least on my opinion, we need to introduce a virtual host for each client in SICF. But how do I make it happen?
Regards
Di -
Please Help, I want to change field value in a table, based on another field value in the same row (for each added row)
I am using this code :
<HTML>
<HEAD>
<SCRIPT>
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for(var i=0; i<colCount; i++ ) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[1].cells[i].innerHTML;
switch(newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
break;
case "checkbox":
newcell.childNodes[0].checked = false;
break;
case "select-one":
newcell.childNodes[0].selectedIndex = 0;
break;}}}
function deleteRow(tableID) {
try {var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
if(rowCount <= 2) {
alert("Cannot delete all the rows.");
break;}
table.deleteRow(i);
rowCount--;
i--;}}}catch(e) {alert(e);}}
</SCRIPT>
</HEAD>
<BODY>
<INPUT type="button" value="Add Row" onClick="addRow('dataTable')" />
<INPUT type="button" value="Delete Row" onClick="deleteRow('dataTable')" />
<TABLE id="dataTable" width="350px" border="1">
<TR>
<TD width="32"></TD>
<TD width="119" align="center"><strong>Activity</strong></TD>
<TD width="177" align="center"><strong>Cost</strong></TD>
</TR>
<TR>
<TD><INPUT type="checkbox" name="chk"/></TD>
<TD>
<select name="s1" id="s1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</TD>
<TD><input type="text" name="txt1" id="txt1"></TD>
</TR>
</TABLE>
</BODY>
</HTML>Hi,
Let me make sure u r working with table control.
First u have to create a event(VALIDATE) to do the validation.
Inside the event,
1. First get the current index where user has pointed the curson
2. Once u get the index read the internal table with index value.
3. Now u can compare the col1 and col2 values and populate the error message.
1. DATA : lo_elt TYPE REF TO if_wd_context_element,
l_index type i.
lo_elt = wdevent->get_context_element( name = 'CONTEXT_ELEMENT' ).
CALL METHOD LO_ELT->GET_INDEX( RECEIVING MY_INDEX = l_index.
above code should be written inside the event.
Thanks, -
The list contains 250 rows of names and their DoB (Date of Birth) = colum A and B.
The 3r colum should feature the automatically calculated AGE in years only = colum C from TODAY
It is a **** of a job to input the DATEDIFF formula for each cell (of colum C).
Can this be simplified?
Pleas help to find the right solution for Numbers '09 (version 2.1)
ThanksHi Lepe,
Assuming the first row of your table is used for labels (Name, DOB, Age, etc) and the data starts in row 2...
In C2, enter: =DATEDIF(B2,TODAY(),"Y")
Hover the mouse pointer over the Fill Handle (small circle) at the bottom right of the selected cell (C2).
When the mouse pointed turns to a black cross ( + ), click and drag the control down to fill the formula into the rest of the cells in the column.
For a 250 row table, there are other, more efficient ways of filling the formula down the column. These are described in the User Guide section referenced in Jerry's post.
Regards,
Barry -
Grab a list of the latest note for each job when/if they start with set text
How would I look only to the latest [01-JobComment].[Creation_Date] where [01-JobComment].[text] starts with the text "AB001:" for each [05-Job].[Job_ID]?
SELECT [05-Job].Job, [01-JobComment].[CREATION_DATE], Mid([01-JobComment].[TEXT],1,6) AS AB001, [05-Job].Name, [05-Job].Owner, [05-Job].Type, [01-JobComment].CREATED_BY, [01-JobComment].CREATED_BY, [05-Job].Status, [05-Job].Owner
FROM [05-Job] INNER JOIN [01-JobComment] ON [05-Job].Job = [01-JobComment].JOB_ID
WHERE ((([01-JobComment].[CREATION_DATE])>[05-Job].[AsBuiltProof]) AND ((Mid([01-JobComment].[TEXT],1,6))="AB001:"))
ORDER BY [01-JobComment].[CREATION_DATE];I'm not sure this is what you want:
SELECT [05-Job].Job, (SELECT Max(T.CREATION_DATE) FROM [01-JobComment] AS T WHERE T.JOB_ID=[01-JobComment].JOB_ID AND Left(T.[text],6)='AB001:') AS CreationDate, Left([01-JobComment].[TEXT],6) AS AB001, [05-Job].Name, [05-Job].Owner, [05-Job].Type, [01-JobComment].CREATED_BY,
[05-Job].Status
FROM [05-Job] INNER JOIN [01-JobComment] ON [05-Job].Job = [01-JobComment].JOB_ID
WHERE [01-JobComment].[CREATION_DATE]>[05-Job].[AsBuiltProof] AND Left([01-JobComment].[TEXT],6)="AB001:"
ORDER BY [01-JobComment].[CREATION_DATE];
Regards, Hans Vogelaar (http://www.eileenslounge.com) -
Do we need to create Storage Bins for each Client?
Hi,
I have defined the storage bin structure etc which I could transport.
But does the creation of bins (using LS01N) need to be done separately for each client? If on the test client we dont have access to Create Bins then what is the right approach to get it done.
Thanks.Thanks. I tried using LS05.
What entries should I make?
I entered Warehouse and Storage Type
The Default Session was showing as RLLS0500 and I left it as it is.
But I am getting Error message "Check you entry for manual storage bin creation".
Any suggestions?
Thanks. -
How to dump block and identify the bytes stored for each column
SQL> select header_file, header_block
2 from dba_segments
3 where segment_name = 'APARTMENTS';
HEADER_FIL HEADER_BLO
4 1692
1 row selected.
SQL> alter system dump datafile 4 block 1693;
Statement processed.
How can I see the dump block and identify the bytes stored for each column?
tab 0, row 0, @0x73b
tl: 125 fb: H-FL lb: 0x1 cc: 4
col 0: [25]
52 65 64 77 6f 6f 64 20 53 68 6f 72 65 73 20 41 70 61 72 74 6d 65 6e 74 73
col 1: [20] 00 54 00 01 02 08 00 00 00 01 00 00 00 01 00 00 00 00 1b 8d
col 2: [53]
00 54 00 01 02 0c 00 00 00 01 00 00 00 01 00 00 00 00 1b 8e 00 21 09 00 00
00 00 00 00 11 00 00 00 00 00 01 45 6d 65 72 67 65 6e 63 79 20 44 65 74 61
69 6c 73
col 3: [20] 00 54 00 01 01 08 00 00 00 01 00 00 00 01 00 00 00 00 1b 8fSQL> select header_file, header_block
2 from dba_segments
3 where segment_name = 'APARTMENTS';
HEADER_FIL HEADER_BLO
4 1692
1 row selected.
SQL> alter system dump datafile 4 block 1693;
Statement processed.
How can I see the dump block and identify the bytes stored for each column?
tab 0, row 0, @0x73b
tl: 125 fb: H-FL lb: 0x1 cc: 4
col 0: [25]
52 65 64 77 6f 6f 64 20 53 68 6f 72 65 73 20 41 70 61 72 74 6d 65 6e 74 73
col 1: [20] 00 54 00 01 02 08 00 00 00 01 00 00 00 01 00 00 00 00 1b 8d
col 2: [53]
00 54 00 01 02 0c 00 00 00 01 00 00 00 01 00 00 00 00 1b 8e 00 21 09 00 00
00 00 00 00 11 00 00 00 00 00 01 45 6d 65 72 67 65 6e 63 79 20 44 65 74 61
69 6c 73
col 3: [20] 00 54 00 01 01 08 00 00 00 01 00 00 00 01 00 00 00 00 1b 8f -
How can i pull the payment transactions for each invoice?
Hi folks
iam developing report for following requirement.
want to disply the vendor transaction file for all company codes Fiscal year,of 2004,2005,2006, and 2007 (to date).
The purpose of oureport is to analyze our company invoices and investigate potential overpayment opportunities. In order to effectively accomplish this, we need a single invoice record for each invoice that was received by compnay from their vendors. The single invoice record would contain at least the following columns: Vendor Number, Vendor Invoice Number, Invoice Date, Invoice Amount, SAP Document Number, Check/Wire Number, Check/Wire Date, Check/Wire Amount. SAP would have multiple rows in a table for any one invoice, whereas we would only want to see ONE row for every vendor invoice.
if you know that company pays (for example) 75,000 invoices/year - then the transaction file you would have about 300,000 records in it. 75,000 Invoices * 4 years.
inodrer to develop this report iam using table PAYR -payee
BSIK ( closed items) BSAK ( open items).
my question is any one tell me how can write logic to pull the payment transactions for each invoice?
regards
neeruHi rob,
yes you are right, an invovice may contaion duplicate records
example PAYR table contain
invice no compnay code checkno vendor fisclyear
( doc.number)
2000134373 001 10287200 2007
2000134373 001 10427890 2007
so as per my requirement how can i write the logic.
regards
neeru -
How to use the different class for each screen as well as function.
Hi Experts,
How to use the different class for each screen as well as function.
With BestRegards,
M.Thippa Reddy.Hi ThippaReddy,
see this sample code
Public Class ClsMenInBlack
#Region "Declarations"
'Class objects
'UI and Di objects
Dim objForm As SAPbouiCOM.Form
'Variables
Dim strQuery As String
#End Region
#Region "Methods"
Private Function GeRate() As Double
Return Double
End Function
#End Region
Public Sub SBO_Appln_MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean)
If pVal.BeforeAction = True Then
If pVal.MenuUID = "ENV_Menu_MIB" Then
End If
Else ' Before Action False
End If
End Sub
#End Region
End Class
End Class
Rgds
Micheal
Vasu Anna Regional Feeling a???? Just Kidding
Edited by: micheal willis on Jul 27, 2009 5:49 PM
Edited by: micheal willis on Jul 27, 2009 5:50 PM -
How many emails can I have on my account?
Can I have client folders for each client to access their own survey/forms?
Can I customize for each client?
Do we need multiple subcription accounts for this?You need to have one FormsCentral subscription per email.
At this time FormsCentral doesn't support folders.
Gen
Maybe you are looking for
-
Hi friends some of the employees has retire/separate in may 2008 but in september their provident fund is coming wage type are /3F3 Er PF contribution =65 /3F4 Er Pension contribution = -65 same scenario is coming for some employees. please advis
-
Error message when attempting to publish page with flash content in cs6
Good day, I have a number of websites that I have created with content from previous versions of flash that I have installed in my html pages. This year I have been repeatedly frustrated by the flash movies working on my computer then not working af
-
Transaction fails in pay pal sandbox account
I have created a pay pal sandbox account viahttps://developer.paypal.comand the account has been created successfully. It automatically creates two account one for buyer and seller in accounts section. I tried to do some test with transactions as my
-
Dear rich, anji, r@a and all Experts, i have three t-code zaa1 for create, zaa2 for change, and zaa3 display, in zaa2 suppose i dont make any chages and click on BACk button then it directly come out from that tcode , and if i make any chages and c
-
MAC PowerPC G4/MAC OS 10.4.11/ AICS3/640 MB SDRAM I've had an ongoing problem when stroking type (both fonts and type that's been turned to outlines) since I upgraded to AI-CS3. The stroke, especially if it's thinner than .002" does not uniformly out