Minimum value row
I have a table as follows
Temp
col1 col2 col3 col4
999 0909 1 a
999 0909 2 r
999 0202 1 aaa
999 0202 2 bbb
999 0303 2 khp
999 0303 3 lkp
999 0404 4 pppHow can I extract min(col3) row from temp.
Expected rows from the table
999 0909 1 a
999 0202 1 aaa
999 0303 2 khp
999 0404 4 pppPlease help
Hi,
Do you want
the lowest col3, and whatever value of col4 happens to be on the same row with the losest c3, or
the lowest col4, and whatever value of col3 happens to be on the same row with the losest c4? Solomon assumed this, so I will, too.
The results happen to be the same in the small set of sample data you posted.
What results would you want from these two additional rows?
select 999,'9876',2,'aaa' from dual union all
select 999,'9876',1,'zzz' from dual union all?
The solution Solomon posted (perhaps with col3 and col4 reversed) is perfect for the question you asked.
If you have several columns like col3, which are not involved in the decision about which rows to display, but have to be displayed, then you have to repeat the KEEP (DENSE_RANK stuff for every column. That can be tedious.
Here's another way that's good if you have a lot of columns in the row:
WITH got_rnum AS
SELECT t.*
, RANK () OVER ( PARTITION BY col1
, col2
ORDER BY col4
) AS rnum
FROM t
-- WHERE ... -- any filtering goes here
SELECT * -- or list all columns except rnum
FROM got_rnum
WHERE rnum = 1
;Edited by: Frank Kulash on Dec 9, 2009 8:14 PM
Similar Messages
-
Displaying the name of a minimum value in crosstab
Hi,
we have a crosstab with [Job Number] in the left column, [Quantitiy Break] as the column headers and (min[bid value]) as the measure.
We want to display the name of the [vendor] who gave the minimum bid alongside the measure in the crosstab.
we have tried allsorts of formula along the lines of:
=[Vendor] Where ([Bid Value Row]=(Min([Bid Value Row])))
=[Vendor] Where ([Bid Value Row]=(Min([Bid Value Row] ForEach ([Job Number]))))
=[Vendor] Where ([Bid Value Row]=(Min([Bid Value Row] ForEach ([Job Number];[Quantity Break]))))
etc
can anyone help?
thanks very much
KeithYou could try the method I use to pull this back from the database in one go...
Create an object
start with bidvalue (aggregated on the right level, formatted as string,
make sure you use leading zeroes and room enough for the highest possible value)
and concatenate the vendor after that.
Now use right(min(new object);lenght(new object)-length bidvalue string)
(might have tweak a bit to get the exact vendor part of the string, this is from the top of my head,
but no doubt you'll get it to work)
This will find the combination with the minimum bidvalue, but only return the vendor part.
Hope this helps,
Marianne -
Select Query with minimum values
Table name: employess_inout
Column name: employee_code number(data type)
IN_Time date(data type)
Out_time date(data type)
i want to select only in_time coloumn data with min intime as in one date A employee have more then 2 times in_time entry
example
employee_code in_time out_time
1 18-mar-12 08:15:21 18-mar-12 13:02:01
1 18-mar-12 14:07:46 18-mar-12 18:01:32
1 19-mar-12 09:15:11 19-mar-12 12:58:54
1 19-mar-12 14:10:01 19-mar-12 16:21:57
1 19-mar-12 16:53:37 19-mar-12 18:15:33
In above example I only want to select in_time column values which is minimum as 18-mar-12(08:15:21) like wise in date 19-mar-12 minimum value is 09:15:11.
Please write the script.
thanks in advanceDear Frank Kulash
the Script is
Select ei.emp_code,p.ename, d.department_name, ds.designation_name,
to_char(ei.intime, 'dd') "IN_Date",
to_char (ei.intime,'hh24:mi') "IN_Time" /*here i used "min" but not solved*/
FROM einout ei, personnel p,departments d, designations ds
where ei.emp_code = '470'
and intime between to_date ('01/03/2012 08:10', 'dd/mm/YYYY hh24:mi')
and to_date ('21/03/2012 10:00','dd/mm/YYYY hh24:mi')
and ei.emp_code = p.emp_code
AND p.dept_code = d.dept_code
and p.desig_code = ds.desig_code
group by ei.emp_code,p.ename, d.department_name, ei.intime,ds.designation_name --, ei.outtime
order by ei.intime, ei.emp_code asc;
Out Put
EMP_CODE ENAME DEPARTMENT_NAME DESIGNATION_NAME IN_Date IN_Time
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 01 09:15
*470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 02 08:58*
*470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 02 14:04*
*470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 02 15:11*
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 03 09:06
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 05 17:07
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 06 09:47
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 07 09:36
*470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 07 19:39* 470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 08 12:16
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 09 09:26
*470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 09 14:08*
I want to take out put
like that
EMP_CODE ENAME DEPARTMENT_NAME DESIGNATION_NAME IN_Date IN_Time
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 01 09:15
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 02 08:58
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 03 09:06
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 05 17:07
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 06 09:47
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 07 09:36
I only need min time (value) once of A date.
[Bold rows are no need in output]
please tell how it will be possible -
PARTITION BY ? Return an ID based on the minimum value of another column
Hi guys
I want to return the ID column of a row, where 2 other columns = a set value, and a 3rd column has the minimum value matching the other criteria.
so in effect :
with t as (
select 1 dst_id, 'abc' dst_title, 1 edition_from, 1 media_item from dual
union all
select 2 dst_id, 'abc' dst_title, 1 edition_from, 2 media_item from dual
union all
select 3 dst_id, 'abc' dst_title, 2 edition_from, 1 media_item from dual
union all
select 4 dst_id, 'abc' dst_title, 2 edition_from, 2 media_item from dual
union all
select 5 dst_id, 'def' dst_title, 1 edition_from, 1 media_item from dual
union all
select 6 dst_id, 'def' dst_title, 1 edition_from, 2 media_item from dual
select dst_id
from t
where dst_title = 'abc'
and edition_from = 1
and media_item = minimum value of media item using above where clauseWould return dst_id = 1 because it has the minimum media item value of 1 where dst_title = abc and edition_from = 1
Can this be done in 1 query ? I've been trying it using partition by and over dst_title, edition_from but that doesn't work.
I'm currently doing it using a sub query or 2 queries, but thought there must be a way to do it in one ?
Thanks all
ScottLike this?
SQL> with t as (
2 select 1 dst_id, 'abc' dst_title, 1 edition_from, 1 media_item from dual
3 union all
4 select 2 dst_id, 'abc' dst_title, 1 edition_from, 2 media_item from dual
5 union all
6 select 3 dst_id, 'abc' dst_title, 2 edition_from, 1 media_item from dual
7 union all
8 select 4 dst_id, 'abc' dst_title, 2 edition_from, 2 media_item from dual
9 union all
10 select 5 dst_id, 'def' dst_title, 1 edition_from, 1 media_item from dual
11 union all
12 select 6 dst_id, 'def' dst_title, 1 edition_from, 2 media_item from dual
13 )
14 select dst_id
15 from (select t.*
16 , row_number() over (partition by dst_title, edition_from order by media_item) rn
17 from t
18 where dst_title = 'abc'
19 and edition_from = 1)
20 where rn = 1;
DST_ID
1
SQL> -
Hi everybody,
Here is a dilemma Im experiencing. Below is an excerpt from the report, where you can see one Characteristic (Product Class) and one KeyFigure (RWA min). The cube content for the data in the excerpt are 4 rows (see below).
In the properties for the KF (RWA min) the Calculated Single Value as has been set to Minimum, however in the report the sum of all values in the cube is shown.
The exception aggregation for the KF is set to Summation so my conclusion is that this might be the reason. However I cant set the exception aggregation to Minimum, since I have to reference it to a Characteristic, which I dont have. Any suggestions on how to solve this? I simply want the minimum value!
Report:
Product Class .....RWA min
01 (On balance) ... 4.168,78 EUR
Cube:
Product Class .RWA Before Mitigation
1 .......3.038,07
1 ......750,00
1 ......380,71
1 .....0,00
Total. . ...4.168,78Hi Dan,
Do you want to see just one, min value? In this case you may use a 'Bottom N' condition with n=1.
If it is not so, what kind of report (example) would you like to get?
Best regards,
Eugene -
Minimum value without counting those with 0 values: help!
Hi Experts,
I need your help. I want to list only the minimum value for kf A but not counting 0 values. The minimum value is based on order #. For example, I want to see the minimum order amount(kf A) for this week, not counting 0. I can't use conditions because it would just remove that particular row from the result. For example, if I put a condition that kf A > 0. Then the result would yield nothing. This is aggregate data for 1 week period. I only need a summarize report stating that for week x, I have the lowest order of $$$(not zero), and listing all doc # on the report is not an option. I also tried, multiply (kf A ==0)*99999, through formula kf, and that didn't work either.
I haven't tried virtual key figure or adding another kf to cube - those are options that I afraid to tackle right now.
Any help is appreciated,
Thanks.Hi,
Try to use Exception aggregation to aggregate based on order #.
In the condion you put key figure value > 0.
Regards,
Vivek -
How to get all minimum values for a table of unique records?
I need to get the list of minimum value records for a table which has the below structure and data
create table emp (name varchar2(50),org varchar2(50),desig varchar2(50),salary number(10),year number(10));
insert into emp (name,org,desig,salary,year) values ('emp1','org1','mgr',3000,2005);
insert into emp (name,org,desig,salary,year) values ('emp1','org1','mgr',4000,2007);
insert into emp (name,org,desig,salary,year) values ('emp1','org1','mgr',7000,2007);
insert into emp (name,org,desig,salary,year) values ('emp1','org1','mgr',7000,2008);
insert into emp (name,org,desig,salary,year) values ('emp1','org1','mgr',7000,2010);
commit;
SELECT e.name,e.org,e.desig,min(e.year) FROM emp e,(
SELECT e1.name,e1.org,e1.desig,e1.salary FROM emp e1
GROUP BY (e1.name,e1.org,e1.desig,e1.salary)
HAVING COUNT(*) >1) min_query
WHERE min_query.name = e.name AND min_query.org = e.org AND min_query.desig =e.desig
AND min_query.salary = e.salary
group by (e.name,e.org,e.desig);With the above query i can get the least value year where the emp has maximum salary. It will return only one record. But i want to all the records which are minimum compare to the max year value
Required output
emp1 org1 mgr 7000 2008
emp1 org1 mgr 7000 2007Please help me with this..Frank,
Can I write the query like this in case of duplicates?
Definitely there would have been a better way than the query I've written.
WITH got_analytics AS
SELECT name, org, desig, salary, year
, MAX (SALARY) OVER ( PARTITION BY NAME, ORG, DESIG) AS MAX_SALARY
, ROW_NUMBER () OVER ( PARTITION BY NAME, ORG, DESIG, SALARY
ORDER BY year DESC
) AS YEAR_NUM
FROM (SELECT 'emp1' AS NAME, 'org1' AS ORG, 'mgr' AS DESIG, 3000 AS SALARY, 2005 AS YEAR FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',4000,2007 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',4000,2008 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',7000,2007 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',7000,2007 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',7000,2008 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',7000,2010 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',7000,2010 FROM DUAL)
SELECT name, org, desig, salary, year
FROM got_analytics
WHERE salary = max_salary
AND YEAR_NUM > 1
Result:
emp1 org1 mgr 7000 2010
emp1 org1 mgr 7000 2008
emp1 org1 mgr 7000 2007
emp1 org1 mgr 7000 2007
WITH got_analytics AS
SELECT name, org, desig, salary, year
, MAX (SALARY) OVER ( PARTITION BY NAME, ORG, DESIG) AS MAX_SALARY
, ROW_NUMBER () OVER ( PARTITION BY NAME, ORG, DESIG, SALARY
ORDER BY year DESC
) AS YEAR_NUM
, ROW_NUMBER () OVER ( PARTITION BY NAME, ORG, DESIG, SALARY, Year
ORDER BY YEAR DESC
) AS year_num2
FROM (SELECT 'emp1' AS NAME, 'org1' AS ORG, 'mgr' AS DESIG, 3000 AS SALARY, 2005 AS YEAR FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',4000,2007 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',4000,2008 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',7000,2007 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',7000,2007 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',7000,2008 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',7000,2010 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',7000,2010 FROM DUAL)
SELECT name, org, desig, salary, year
FROM got_analytics
WHERE salary = max_salary
AND YEAR_NUM > 1
AND YEAR_NUM2 < 2
Result:
emp1 org1 mgr 7000 2008
emp1 org1 mgr 7000 2007 -
Finding a minimum value in an array without using loops
I can find a minimum value in an array using a loop, but I am unsure of how to do it without any type of of loop
Here is what I have using a loop:
// This method searches for the minimum value in an array
public static int min(int a[]){
int min = a[0];
for(int i = 1; i < a.length; i++){
if(a[i] < min){
min = a;
return min;
How do I covert this to do the same thing, using no loops?
Thank you for replies
Edited by: kazmania on Feb 7, 2008 12:26 PMpublic class Test112 {
public int recurse(int[] x, int i, int n)
if (i==x.length-1) { return (x[i] < n) ? x[i] : n; }
n = (n < x[++i]) ? n : x;
return recurse(x, i, n);
public static void main(String[] args) {
int[] nums = {3, 1, 56, 2, 99, 34, 5, 78, -400, 2383, 201, -9, -450};
Test112 t = new Test112();
int min = t.recurse(nums, 0, nums[0]);
System.out.println(min); -
Error while setting Minimum value to Input Number Spin Box..
Hai
I drag and drop a VO and created a table.In that table,i convert a column which contain an InputText field to Input Number Spin Box.At the time of page load ,the table fetches the datas from the DataBase and showing Number values in the SpinBox.After that,When i scroll the table through vertical scrollBar,the table showing *"fetching data"* and Error is throwing as *"The value must be Number"* .. In the VO,this attribute is Number.
THIS ERROR ONLY OCCURS when i set the Minimum value of spinBox ..The purpose of setting minimum value is that i only want user to select ve value only..How can i restrict the user for selecting only ve values..?(ie,*How can i set minimum value to SpinBox?)*Try changing the datatype of your attribute in the EO to be Double instead of Number.
-
Hi
I have an extractor with 2 primary keys, Indkey and Indcode.
I need to get the minimum value of Indcode and populate the relevant Indkey.
ex, Indkey Indcode
IND001 20
IND002 30
IND003 40
I only need to get the record IND001 20, populated and not the other two. I am populating these values to a DSO in BW.
How can I acheive this? Please give the algorithm or sample code.
Thanks
Sirishasort table by key1 key2 and read table index1
-
Charge sales order value with a minimum value
Dear All,
I have one requirement where I would like to charge my sales order value with a minimum value. For example, a minimum sales order value requirements are set at $1,400.00 (the minimum values can be different based on the different materials) per order, if the value of the order exceeds $1,400.00, therefore no minimum fee is applied or displayed and the customer is charged the actual value of the order; if the value of the order is less than the minimum thus the customer is charged the minimum. We also can set the minimum as quantity.
Is there any standard functionality through which this can be done.. or any suggestion?
Your help is highly appreciated.
Thanks and best regards,
JoYou can maintain the Condition Record with Condition Type as AMIW wrt to Division & Price Group.You can change the Accesses as per your requirements.
Best Regards,
Ankur -
How to give a checkbox the value "row number" (like [row selector])
I like to define a checkbox with htmldb_item.checkbox and give the checkbox the value 'row number'.
It has to be the row number as displayed. Therefore I cannot use rownum or row_number() because the htmldb sorting functionality change the sequence after the row numbers are given.
How can I give the checkbox this value, or as alternative how can I get the current row (checkbox element) in javascript from the checkbox onclick event.Vikas,
Thanks a lot.
This works.
I use this number also to construct javascript and I walk in problems which are also solved now.
therefore for anyone else who also want to use '#ROWNUM#'. keep in mind that for the sql #ROWNUM# is just a string and should be treated as a string therefore use quotes around it. The #ROWNUM# string is translated after executing the query, when the page is constructed from the result of the query.
Fred. -
How to capture the data within the given range of maximum and minimum values ? from csv files
My requirement,
1. Here, the user will provide the range like maximum and minimum values, based on this range, the VI should capture the data within the given range. ( from CSV file as attached )
2. Then VI should calcluate the average value for captured data and export it to excel.
This is my requirement can anyone help me on this.
Many thanks in advance
rc_cks
Attachments:
sample_short.csv 2439 KBHi,
Thanks for remnding me. I forgt to attach the VI,
Here I am attaching the VI, what I tried.
From attached CSV file, I have to find an average value for columns B,C,D,E,F,G,H,I and AJ, AK. ( data range will be defined by user ), focused only on these columns
Here, the scope is to calculate an average value for given data range by user as MAX and MIN data.
FYI: I tried manually for two instance i.e column H & I. As per H column one steady state values from 7500 to 10500 and similarly in I column 7875 to 10050. So, I gave these as a limit to capture and calculate the average value. But unfortunaltely, requirement has been modified as per below requirements.
More Info on requirement:
--> The user will define the range of data by giving some MAXIMUM and MINIMUM values(for above mentioned columns induvidually), then VI should capture that data range and it has to caculate the average value for that range of data. This is the task I have to complete.
--> I am stuck in creating a logic for data capturing for given range of MAX and MIN value from user,
Can anyone help me on this.
If my explanation is not clear, Please let me know.
Many thanks, help mw
rc
Attachments:
VI_rc.vi 25 KB
sample.zip 4166 KB -
Minimum Value Sucharge not calculated
Hi Gurus,
I created condition record ZMIW for material 1234 1000 Euro but in the Salesorder Condion Tab
SD Minimum Value Sucharge is same with Minumum Order Value
Mat 1234 1 pc 200 Euro
Minimum Order Value 1000 Euro
Minumum Minimum ValueSurchrg 1000 Euro (it should be 800 Euro)
I use the Condition types ZMIW and ZMIZ
In the Pricing Procedure
SubT Reqt Calty acct
817 0 ZMIW Minimum SalesOrdrVal D 2
818 0 ZMIZ Minimum ValueSurchrg 2 13 ERS
RefCondtTyp is ZMIW fpr CondType ZMIZ
Could please tell what should I check ?
BR,
Emre
Edited by: Y. Emre Kurnaz on Sep 11, 2009 9:00 AM
Edited by: Y. Emre Kurnaz on Sep 11, 2009 9:01 AMHi,
thank you for your reply.
I maintained the Condtyp ZMIW and ZMIZ
ZMIW from 800 subtotal D and requirement 2. i typed step number 800 (where Net Value for Item calculated).
ZMIZ requirement 2 and altcalc type 13
I maintained Condition record for ZMIW 1000 Euro.
everything looks right. but minimum order value and surchage are same (both are 1000 Euro.)
I tried with standard pricing procedure (RVAA01) the result is equal
I donkt know but it should not be so complex.
Thanks in Advance
Emre -
Minimum Values in Billing Doc - Consolidated Invoice - How to exclude items
I have a requirement to apply a minimum charge to an invoice but the minimum amount is not to be based on the total value of the invoice.
The invoice is used to bill a rental contract via a billing plan, via deliveries based on actual usage and other manually entered transactions. All these contribute to the minimum value.
The invoice is also used to bill other debit notes during the period but their value MUST not be included when the minimum value is to be determined.
The minimum pricing condition is working as standard SAP, BUT I need to exclude the value of some of the line item. I can distinguish which item are to be excluded by the preceding document type.
Anyone has any idea of how to do this?
Regardsquestion marked as answered because it is no longer required.
Maybe you are looking for
-
Forms Created in Pro 10 cannot be signed in Reader 11
Hello, I have created forms using Adobe Pro 10 with signature fields. Users who recently were upgraded to Reader 11 can no longer sign the form. They can enter data into text fields - but when reviewing the form properties it disallows digital sign
-
I am new to Motion and getting a pretty good handle on it, but I could work more efficiently if I knew some short-cuts. For example when I have a clip selected can I toggle back and forth from it's in and out points. In FCP I use Shift-I or O to do t
-
Uninstalling Camera Raw 8.4 RC CC
Can soemone please tell me the necessary steps to remove Camera Raw 8.4 RC for Photoshop CC completely so that I can restore Photoshop back to using Camera Raw 8.3. I use MacOSX 10.92 . Thanks Trevor Craig
-
New XSL processor release 2.2.0.8 ?
When can we expect the XSL processor release (2.2.0.8 ?) with the multi-thread bug fix? Thanks, null
-
Weird Macbook Pro Unibody Trackpad problem
Okay, this has been bothering me for a while. I have a 2 year old Unibody 15" Macbook pro, with the glass trackpad. I used the laptop for a year, and it was perfect. One day I was sitting on the couch with the computer next to me and I push the track