Query to get row with max values for distinct
I have a table test with ID, ADID, MTMST columns.
ID ----ADID---- MTMST
1 ----100---- 24-MAR-12 08.17.09.000000 PM
1 ----101---- 24-MAR-12 08.18.15.000000 PM
1 ----102---- 24-MAR-12 08.18.56.000000 PM
2 ----103---- 24-MAR-12 08.19.21.000000 PM
2 ----104---- 24-MAR-12 08.19.36.000000 PM
2 ----105---- 24-MAR-12 08.19.46.000000 PM
3 ----99---- 22-MAR-12 09.48.22.000000 PM
I need the rows with max ADID for each ID.
I used the following query but it provided max ADID of the table but not the distinct ID
select * from test where ADID in (select max(ADID) from test where id in (select distinct(id) from test where mtmst > sysdate -1))
Result:*
ID ----ADID---- MTMST
2 ----105---- 24-MAR-12 08.19.46.000000 PM
Expected result:*
ID ----ADID---- MTMST
1 ----102---- 24-MAR-12 08.18.56.000000 PM
2 ----105---- 24-MAR-12 08.19.46.000000 PM
Thanks,
Dheepan
Edited by: Dheepan on Mar 24, 2012 9:53 AM
select id, adid, mtmst from test where (id, adid) in (select id, max(adid) from test group by id) and MTMST>sysdate-1
is the answer.
Similar Messages
-
Counting one of multiple rows with same value for same ID
Hello,
I have this query:
SELECT
count( case when EXISTS (
SELECT *
FROM business_log bl, subject su
WHERE su.ID_SUBJECT = s.ID_SUBJECT
and bl.id_subject = su.id_subject
AND bl.value = 'Solved'
then 1 else null end) num_solved
FROM subject s
It is posible that one subject is more than once 'Solved' in table BUSINESS_LOG
I want to count only one row solved for one subject.
I must to use only SUBJECT table in the main query because of other counts.
Thank You very much.
Regards
Milos
Message was edited by: 2796614so in case you have no solved entry...you get NULL back instead of 0.....
and....there is no need for the group by ....as you are only looking for one subject
SELECT COALESCE((SELECT max(1)
FROM business_log bl
WHERE bl.id_subject = s.id_subject
AND bl.value = 'Solved'),0) num_solved
FROM subject s
but....I would like to have a proof, that this one is faster than the outer-join solution.
So...perhaps we'll see an execution plan for both of them.
corrected....missing bracket -
Using a table alias to identify row with max timestamp for same ID, syntax?
Hello experts
I have created an alias of a table, so now I have table T1 and its alias T2. (T2 is not joined to anything in the universe currently)
I need to identify the row from T1 with the maximum timestamp for any given ID:
ID Timestamp
1 2011-01-24 16:26:00.000
1 2011-02-24 14:21:00.000
1 2011-02-24 13:49:00.000
I couldn't find anything on the SAP forums, but elsewhere suggested my approach should be thus:
1) Create a table alias (leave it free standing i.e. not joined) - DONE
2) For T1, create a dimension object named Timestamp - DONE
3) Create a seperate predefined condition icon funnel / filter - in the where clause:
T1.timestamp = (SELECT max(T2.timestamp) from T2 WHERE
T1.Key = T2.Key)
I'm stuck with the BO XI 3.1 syntax on step 3. I can't get it to parse.
In the where clause, mine starts with @select(T1\Timestamp) = max(@select(T2\Timestamp)
@where T1.Claim_no = T2.Claim_no)
Please can someone help me with the syntax so this thing will parse.
Many thanks in anticipation.
EddieHi ,
Can you try
SELECT ID, MAX(datetime) FROM T1 GROUP BY by ID
Thanks
Ponnarasu -
How to develop this report/Query that selects records with MAX Value
Hi,
My requirment is to develop a report to show all emp whose policy is going to expire ith in the user selected date intreval...
Emp_ID--App_Date-Policy_Strt_Date--Policy_End_Date--App_Status
101.01.2007---BlankBlank--
NEW (New application for a Medical Insurance policy raised for employee)
101.01.2007---01.02.200730.05.2007--
COMPLETE (policy issued for emp with strt & end dates)
115.05.2007---01.02.200730.05.2007--
RENEWAL (a application is raised to renew emp policy)
115.05.2007---01.06.200731.12.2007--
COMPLETE (policy issued for emp with strt & end dates)
115.12.2007---01.06.200731.12.2007--
RENEWAL (a application is raised to renew emp policy)
115.12.2007---01.01.200831.05.2008--
COMPLETE (policy issued for emp with strt & end dates)
115.05.2008---01.01.200831.05.2008--
RENEWAL (a application is raised to renew emp policy)
115.05.2008---01.06.200831.05.2009--
COMPLETE (a application is raised to renew emp policy)
So EMP 1 got valid policy untill 31.05.2009.
When a user executes a query to show all employees whose policy expiry date intreval (01.05.2008 to 31.05.2008)
it shouldn't show Emp 1 as he got valid policy untill 31.05.2009 but currently it is showing Emp 1....
How can i achieve this
ThanksHi
Thanks for the update
I created variable on Plc End end
If user enter show all emps whose policy is expiring in MAY (01.05.2008---31.05.2008) it is displaying EMp 1 as well but emp 1 has a policy which expires in 2009
Thanks -
Pro*C & SQLDA with NULL value for predicate column
Hi: I am using a C program to update a table via a dynamic sql (method 4) and SQLDA. In the update statement predicate, I have place holders (as in TBLCOL=:C000). One of the columns in the predicate contains null values, so I set L[n] = 0, V[n] = pData (which pData[0] = '\0'), *(I[n]) = -1, and T[n] = 5 (for text). I cannot find the row that I know is there.
I cannot change my statement to contain TBLCOL IS NULL, since I don't know ahead of time if I'm looking for rows with null values for this column. The Pro*C manual says that by setting the appropriate *(I[n]) = -1, it indicates to Oracle to simulate the "IS NULL" clause, and update the appropriate rows. In my case, I receive 1403 as SQLCODE when I use TBLCOL=:C000 vs TBLCOL IS NULL. What am I doing wrong? Thank you for your help.You should include these columns as well;
ChangeType (see mxi_changetype)
ValOwner (repository)
UserID ("jobid=<>", usermskey, GUI (mmc), DG (dyngrp), reconcile)
IdAudit (This is the event task (add and del member for assignments)
ParentAuditId (AuditID of parent which last updated the attribute, not consistent)
ChangedBy (Holds the MSKEY of the user which last changed the attribute)
ExpiryTime
to make sure you get a fuller picture of the audit record.
Your selection does not cover all events and descriptions
br,
Chris -
Hello,
We are creating a cross tab report, with products as the columns, and relationship managers with direct and shared revenue displayed across the rows.
For Eg
Relationship Manager Coverage Product1 Product2 Product3 Product4
Bob Direct 100, 0, 35, 50
Shared 0, 0, 15, 0
Alex Direct 15, 25, 40, 10
Shared 5, 0, 5, 0
George Direct 0, 0, 0, 30
Shared 0, 0, 0, 5
The problem lies when either one of the products has no values, or one of the relationship managers has no direct or shared revenues. If one of the products has no revenues, it disappears, and also when one of the RMs has no direct or shared revenues, the Direct or Shared row disappears.
I have tried to create a second query just included the Coverage variable, and using this variable in Query 2 with the RM variable from query 1, along with checking the "Show Rows with Empty Measure values", "Show Rows with Empty Dimension Values" and "Show when empty", but it still does not appear to work.
It only shows rows with values in them, and shows the rows with empty values at the end with no RM.
I have not tried to solve for empty columns yet.
Help with this would be much appreciated!!!!!!!!
Thank youHi ,
I think you can resolve this issue following ways ,
you need create another query ( Ex :Qauery2 ) add Product object and RM (Direct,shared) object only without conation. So now query2 result wil have all product and RM(Direct,shared).
Merge the Product object and RM between query1 and query2
Now create table using Product and RM from query2 and measure value from query1. Now you will get row even there is no data.
If you want try this sample report using efasion unvierse.
1) Add year ,state and Discount objects and apply condition Year Not in list "2004" and state Not in list "California "
2) run this query and create the cross tab table . Now you will not get 2004 column and California row in table.
3) Create query2 add Year and State only without any condition , run the query. Now query 2 will display all state and year .
4) Merge the column Year and State between query1 and query2
4) Create the cross table ussing Year and state from query2 and Discount from Query1
Now cross table will show 2004 and California ,even there is not in query 1.
I hope this will help you.
Ponnarasu
Edited by: ponnarasuk on Dec 7, 2011 12:48 PM -
Returning 250 rows with 1000 Values in "IN" Clause Oracle 10g On IBM AIX !!
Hi,
Recently we have done the OS migration of Oracle 10g Server from Windows Server to IBM AIX. Everything is fine, But today we came across one crucial bug in the code, i.e In the Select Query, though we're expecting 1000 rows with 1000 values in "IN" Clause , It's returning Only 250 rows. Where as it's returning 1000 rows in Windows Environment with 1000 values in "IN" Clause. I have browsed throgh Google for the resolution but failed to get that.
This is something like,
In Oracle 10g On windows :-
select * from emp
where dept_id in (1,2,3,...................1000);
Assuming there are the dept_id values in Emp table from 1 ... 1000, It's returning 1000 rows.
In Oracle 10g On IBM AIX ,
select * from emp
where dept_id in (1,2,3,...................1000);
Assuming there are the dept_id values in Emp table from 1 ... 1000, It's returning 250 rows. Pls help me, what could be the reason for this. and what needs to be checked to fix this.
Pls suggest !!!
Rajammmh. Did you compared the select count(*) from your_table; in the two cases.
If the result is not good and nobody has deleted rows between migration and your test, you migration need to be replayed.
Which migration did you select, Transportable database or exp/imp...?
Edited by: Dba Z on 16 août 2009 08:56 -
Issue with Negative Value for Total valuated stock 0VALSTCKQTY.
Hi Experts,
we loaded the Cube with datasources 2LIS_03_BX, 2LIS_03_BF and 2LIS_03_UM.
We mapped the quanity field from 2LIS_03_BF in transformation either into Key figures "Quantity issued from valuated stock" (0ISSVALSTCK) or "Quantity received into valuated stock" (0RECVALSTCK ) of the cube.
For obtaining the Total Valuated stock, we used the Key figure 0VALSTCKQTY. This key figure is having the Inflow and Out flow values as 0RECVALSTCK and 0ISSVALSTCK. When i tried to check the content of 0VALSTCKQTY, the key figure 0VALSTCKQTY is not present in the infoCube content. I understood that the value for this key figure would be calculated at the time of query execution with the formula
{ Last obtained Valuated stock + (Received Valuated Stock u2013 Issued Valuated Stock ) }.
The issue is the first records in the query is obtained with negative value for the total valuated stock 0VALSTCKQTY even though the values of Received Valuated Stock and Issued Valuated Stock are with Zero. Could any one please help me on how the first record in the query is with a negative value eventhough the inflow and out flow fields of it are with Zero.
Many Thanks in advance.
JeswanthHi Srini,
I observed an interresting reason for the stock being with negative in the first record.
Issue : While executing the BEx report, we have the first record with a negative value.
Let me explain with an example
Material : XYZ
Plant : A
Date of Stock Initialization for data source 2LIS_03_BX -
> 12th April 2009.
So on 12 Th April 2009 consider that we have a stock in store with a value of 2640.
Then we have loaded wih Data source 2LIS_03_BF for all Historic Movement types.
At the time of query execution we will have the first record with a negative of available stock present on the day of initialization .
So, as we have initilized the data source 2LIS_03_BX on 12 th April 2009, we have at that time a stock of 2640 in availability.
Exactly with the same value of 2640, we are having a negative value i.e. -2640.
and also one more point to be noted is ...as we have initialized the data source 2LIS_03_BX on 12 th APril 2009...it has created a
opening balance of 2640 on the day of initiailization i.e on 12 th April 2009 in infocube....(which is an extra record...)...so if the previous record of 12,04,2009 is having some value in it..then it will get added to 2640 EA..which will give incorrect stock
So in the query the records will appear in the below following manner
Calendar Day Total stock Received stock Issued Stock
28.12.2005 ---> - 2640 EA
29.12.2005 ---> 2000 EA 640 EA 0
10.04.2009 ---> 0 0 2000 EA
11.04.2009 -
> 0 0 0
(For making
the earlier record of initilization to 0 a negative value -2640 EA is created in the first record )
12.04.2009 (Initializtion day) ---> 2640 EA 0 0
13.04.2009
the day before initialization the total stock will be 0 due to the negative effect introduced by the first record and from the day of initialization the records will be the accurate values... On 12 th april 2009 we can see that a stock of 2640 is brought into the total stock. In fact if there is no negative value i.e. -2640 in the first record then ...the value on 11.04.2009 will be 2640 Ea and this will get summed up with the Opening balance of 2640 EA created by 2LIS_03_BX on the day of intitialization. So on 12 .04. 2009 the total stock will be shown as 5280 EA...so in order to prevent the double value only we observed that the first record is created with the negative of available stock present on the initialization ...to make the record before the day of initialization i.e. 11.04.2009...to be 0...so that from 12 th April 2009 ..will start to see the actual total stock in the query result...
This is happening only if we use both the data sources 2LIS_03_BX and 2LIS_03_BF for loading into BW.....
If we load alone by 2LIS_03_BF ...then as 2LIS_03_BX is ruled out in the loading...then no negative of available stock will be created ...because there will be bno opening balance created on the day of initialization.....and the opeing balance available will be flowing into consecutive records due to the movement types and 12 th April 2009 will be shown with avaialable total stock of 2640 EA.
Kindly let us know your opinions on this...
Thanks.
regards,
Jeswanth -
Updating multiple rows with different values
Hi!
I have a problem. I need to update more then 1000 rows with different values. How can I do it?
For exsample i have table:
id; color, date,
1 red
2 green
3 white
I need to update date field.
Update table
set date='01.02.03'
where id=1
Update table
set date='01.03.03'
where id=2
Maybe there is way how to update multiple rows at one query?
Sorry for my bad english.
Thanks!Hi,
You can try this
UPDATE TABLE SET DATE = CASE
WHEN ID = 1 THEN TO_DATE('01-02-03','DD-MM-RR')
WHEN ID = 2 THEN TO_DATE('01-03-03','DD-MM-RR')
ENDcheers
VT -
Query to delete row where column value contains alphabets
Hi,
Could anyone please help me to get this query work.
Query to delete row where column value contains alphabets.
DELETE FROM BIN_ITEM WHERE order_nmb LIKE '%[A-Z]%' || LIKE '%[a-z]%'
Thanks and Regards,
Deekay.RaminHashimzadeh wrote:
SELECT order_nmb FROM BIN_ITEM WHERE regexp_count(order_nmb,'[0-9]') = 0
Ramin Hashimzade
But that won't reject strings like 'gfgG%dgh' which aren't pure alphabetic.
Try:
with test_data as (
select 'ghTYJYEhdfe' str from dual
union
select 'dfF5ssd' from dual
union
select 'rgth*dgheh' from dual
union
select 'ggf{' from dual
union
select 'rwhrhrh' from dual
select *
from test_data
where regexp_instr(str,'[^[:alpha:]]')=0; -
How to get the list of values for a dynamic parameter using Web Services SDK?
<p>I am struggling to get the list of values for a dynamic parameter of a report.</p><p>I am using Java Web Services SDK ... I tried to use PromptInfo.getLOV().getValues() method but it does not work.</p><p>First of all ... is this possible (to get the list of values for a dynamic param) using Web Services?</p><p>Second of all, if this is possible, how should I do it ... it seems it works fine when running the report from CMC. It asks for DB logon info and after that it provides a list of values.</p><p>Thx </p>
<p>Your assumption is correct. We are trying to get the LOVs from the Crystal Report. I was not aware that this is not supported by Web Services SDK.</p><p>We used Web Services SDK to integrated the Crystal Reports in our web application. We implemented some basic actions for reports: schedule, view instances, run ad-hoc reports.</p><p>We encountered this problem when trying to run/schedule reports with dynamic parameters (a list of values from DB). We were unable to get the LOVs.</p><p>Please let me know if you can think of an alternative to look at.</p><p>Thanks a lot,</p><p>Catalin </p>
-
Deleting rows with missing values in field in start routine of update rule
Hello experts,
how can I delet rows with missing values in a specific field in the start routine of update rules?
I think ABAP code should look something like this:
delete ... from DATA_PACKAGE where Z_NO = ''.
thanks in advance for any suggestions!
hizaWrite:
delete data_package where field = value.
Hope it helps.
Regards -
How to get the current month value for a customer exit variable?
How to get the current month value for a customer exit variable?
And also if we have an InfoObject with date value (including date, month, year), then how to derive the month value from this date type of Char.?
Thanks!Hi Kevin,
Check here........
Re: Customer Exist for "From Current Date To Month End"
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/25d98cf6-0d01-0010-0e9b-edcd4597335a
Cal month
Regards,
Vijay. -
How to merge rows with similar values in alv grid display in webdynpro
Hi experts,
i want to know about how to merge rows with similar values in alv grid display of webdynpro.grouping rows is possible in table display in webdynpro but i am not able to do row grouping in the alv grid display in webdynpro.
kindly suggest.
thanks ,
Anita.Hi Anita,
did you find a solution for this? I have opened a Thread, if you know the answer maybe you could help me out:
Is there an ALV function similar to the TABLE Row grouping?
Thanx in advanced!!!
Kind Regards,
Gerardo J -
Jsf page not getting refreshed with updated values?
Hi All,
- managed-bean - session scope.
- On a request, Even though, I am updating the bean's properties(values), my Jsf page is not getting refreshed with updated values as it is displaying the older values.
Can anybody throw some light?
Thanks in advance.
- SriPlease try to give us more information, follow BalusC suggestion.
For this moment I only can say you that the more common cause to this problem (in my expirence) is that you have problems with your conversion/validate phase.
Maybe you are looking for
-
How do I restore a few items saved in Time Machine on a different computer?
After upgrading my G5 Mac to Leopard, and using an external Firewire drive as the Time Machine backup, both of my hard drives crashed on the G5. To make a long story short, I ended up with a new iMac. Luckily, all my data WAS saved on the Time Machin
-
My mac book pro wifi is slow and streaming stops and takes forever to start.
Problem description: wifi seems slow- spinning heel and vision that just stops- sometimes starts and stops again. EtreCheck version: 2.1.8 (121) Report generated April 3, 2015 at 1:01:36 PM EDT Download EtreCheck from http://etresoft.com/etrecheck Cl
-
Loading PNG image file from Applet?
Hi All, My applet running on IE6 and it will often loads 100 PNG image files from a webserver. Size of PNG file is about 60Kb so 100*60=6000 Kb ~ 6M. In theory, the applet will took 6M of memory to store all 100 files. In practical, it tooks about 6M
-
Can we use Windows IIS FTP server in SOA
Can anyone help me out whether we can use windows IIS FTP server in SOA for ftp adapter file transfer operations.
-
Confuse wat to do...
m.. using nokia 701.... and in that left ringer is not working.... i wan't to repiar it but most of the people saying that nokia t-mobile once repair will go on creating a new problm in that.... so plz sugest me as soon as possilble wat shud i do....