Column having minimum value of two calculated columns
Hi All
Please help me out in the following scenario.
I have to get the data from two tables so whatever columns I need put it in the select statement but for two columns I have to do calculations and did assigned an alias name to those two calculated columns, lets say X & Y.
I have to show the data for column Z, the rule for this column is to take minimum value of columns X & Y.
I have to use purely a select statement and retrieve the data. Camnt do any changes or creating functions on database.
thnaks in advance.
@Sven
First thought is using minimum function and throwed me error and then realized that min function can be used on a column and then searched for function to find minimum of calculated columns, could n't find out.
Then thought of using case or if statement to find out the minimum, felt thats not a good idea and also thought of using nested sub query, could n't achieve the desired.
Actually I didnt know about the least function, now I
Anyway thnak you all.
Similar Messages
-
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 -
How to Sort one key figure values in two column based on single char
hi gurus,
I would really appreciate if some one can help me out with my question.
I have to design a query based on a Multiprovider built on three ODS, Purchasing, Confirmations & Invoic ODS
Purchase order Value and Number data in PO ODS, and confirmations is in CONFODS, Invoice Values in INV ODS,
The design of the requirement is
Vendor --> PO --> Material PO Value --> Text PO Value --> Confirmation value --> Invoice value
There are Two POS 1. Material PO & 2. Text PO
I need to display all the Purchase orders for a vendor and in different columns i need to display the value of the Material PO and Text PO and their Confirmation Value and how much is the invoiced value for every PO.
Can anybody tell me what should i do in the Query Designer to display the necessary values.
Thank youHi william,
When i put in the PO KF in the column and also the Confirmation KF in other Column it either shows me # for both the entries or it shows me values in only one of the column
if PO is displayed the Confirmation is not displayed and if Confirmation is displayed PO values are shown as # i dont know what wrong i am doing.
if you have idea can you tell me what i should do when i want two different values from two ODS if there are no characteristics that are matching in either of the ODS should i go for Multi Provider and if so how should be my designing. i would really appreciate if you can tell me taking a scenerio.
Thanks -
From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?
Hi,
Use NVL or COALESCE:
NVL (col_a, col_b)
Returns col_a if col_a is not NULL; otherwise, it returns col_b.
Col_a and col_b must have similar (if not identical) datatypes; for example, if col_a is a DATE, then col_b can be another DATE or it can be a TIMESTAMP, but it can't be a VARCHAR2.
For more about NVL and COALESCE, see the SQL Language manual: http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions119.htm#sthref1310
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002 -
Need to compare values in two columns of one table against values in two columns in another table
Hi, as the title reads, I'm looking for an approach that will allow me to compare values in two columns of one table against values in two columns in another table.
Say, for instance, here are my tables:
Table1:
Server,Login
ABCDEF,JOHN
ABCDEF,JANE
FEDCBA,SEAN
FEDCBA,SHAWN
Table2:
Server,Login
ABCDEF,JOHN
ABCDEF,JANE
FEDCBA,SHAWN
In comparing the two tables, I'd like my query to report the rows in table1 NOT found in table2. In this case, it'll be the 3rd row of table one:
Server,Login
FEDCBA,SEAN
Thanks.create table Table1([Server] varchar(50), Login varchar(50))
Insert into Table1 values ('ABCDEF','JOHN'),('ABCDEF','JANE'),('FEDCBA','SEAN'),('FEDCBA','SHAWN')
create table Table2([Server] varchar(50), Login varchar(50))
Insert into Table2 values ('ABCDEF','JOHN'),('ABCDEF','JANE'), ('FEDCBA','SHAWN')
select [Server] ,Login from Table1
Except
select [Server] ,Login from Table2
select [Server] ,Login from Table1 t1
where not exists(Select 1 from Table2 where t1.[Server] = t1.[Server] AND Login=t1.Login)
drop table Table1,Table2 -
I want to spit cell the value into two separate columns like f_name & l_nam
Hi Guys,
I have excel data in one cell with ',' separated data.
sample data:
empno ename
121 ravi,kann
232 ram,raman
here ename value in one provided in one cell.
Now i want to spit cell the value into two separate columns like first_name and last_name?
Thanks in advance
-LKwith sample_data as
select 121 empno, 'ravi,kann' ename from dual union all
select 232 empno, 'ram,raman' from dual
select empno,
substr(ename,1,instr(ename,',')-1) first_name,
substr(ename,instr(ename,',')+1) last_name
from sample_data; or with regular expressions:
with sample_data as
select 121 empno, 'ravi,kann' ename from dual union all
select 232 empno, 'ram,raman' from dual
select empno,
regexp_substr(ename,'^[^,]*') first_name,
regexp_substr(ename,'[^,]*$') last_name
from sample_data; Edited by: hm on 04.07.2012 06:22 -
Hi All,
Am using OPENROWSET to load the file data into table, here the problem is i need to map same input value to two different columns of table, As format file doesn't allow the duplicate numbers am unable to insert same value to two columns, please help me to
find a solution for this.
i can use only OPENROWSET because i need to insert some default values also which come based on file. only the problem is how to map same input value to two different columns of table. please give me the suggestions.
Thanks,
SudhakarFrom what you say:
INSERT tbl(col1, col2)
SELECT col1, col1
FROM OPENROWSET(....)
But I guess it is more difficult. You need to give more details. What sort of data source do you have? What does your query look like? The target table?
Erland Sommarskog, SQL Server MVP, [email protected]
Hi Erland,
Thanks for your response
my source file is text file with | symbol separate for ex:
1002|eTab |V101|eTablet|V100|Logic|LT-7|Laptops|SCM
Database table have columns like
column1,column2,column3...etc, now i need to insert same value from input file into two columns for ex:
the eTab value from text file has to be insert into column2 and column3 of
table
we cannot change format file like below one
for the above situation how can we insert eTab into column2 and column3
Thanks,
Sudhakar. -
Concatinating the values of two columns ???
Hi,
Can anyone help me out in concatenating the values of two columns ??
Please ASAP...
Thanks>
What's wrong with
select (col X || '-'|| Col y ) as Z from xyz_table;
test@ora>
test@ora>
test@ora> --
test@ora> with xyz_table as (
2 select 1 as col from dual)
3 --
4 select (col X || '-'|| Col y ) as Z from xyz_table;
select (col X || '-'|| Col y ) as Z from xyz_table
ERROR at line 4:
ORA-00907: missing right parenthesis
test@ora>
test@ora>
test@ora> --
test@ora> with xyz_table as (
2 select 1 as x, 2 as y from dual)
3 --
4 select (col X || '-'|| Col y ) as Z from xyz_table;
select (col X || '-'|| Col y ) as Z from xyz_table
ERROR at line 4:
ORA-00907: missing right parenthesis
test@ora>
test@ora>
test@ora> -- ==================================================
test@ora> --
test@ora> with xyz_table as (
2 select 1 as col from dual)
3 --
4 select (col || '-'|| Col) as Z from xyz_table;
Z
1-1
1 row selected.
test@ora>
test@ora>
test@ora> --
test@ora> with xyz_table as (
2 select 1 as x, 2 as y from dual)
3 --
4 select (X || '-'|| y ) as Z from xyz_table;
Z
1-2
1 row selected.
test@ora>
test@ora>isotope -
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> -
One column having multiple values with comma separator.
Hey Guys,
In my db, one culmn having multiple values with comma separator. like column_name = 'value1,value2,value3'. Now I want to compare this column to another column and fetch in Cursor.
and each value having corresponding email_id, By fetching cursor, I need to populate email_ids.
Thanks in advance!!
-LakshmanPlease compare and fetch cursor and populate result with out extract data into temp table. Give me the query!You have not provided DDL for table so I don't know table or column name to write any SQL.
You have not provided DML for test data to run SQL against. -
Single column value into two column of report
Hi frnds,
I have a column of Adress in my databse table from where i have to fetch values and show it a report
able to get report but showing in single column if i take a printout paper will be wasted so I thought of passing these values to two different columns
please help me in giving some suggestionsIn Oracle 9 you can get rid of the regex functions and use traditional SUBSTR, INSTR and REPLACE:
ABSOLUTELY NOT TESTED...
SELECT col1,SUBSTR ( ','||col2||',', instr(','||col2||',',',',lvl)+1,instr(','||col2||',',',',lvl+1)-instr(','||col2||',',',',lvl)-1)
FROM table_name,
(SELECT LEVEL lvl
FROM (SELECT MAX (LENGTH (REPLACE ( col2, ',',''))) mx
FROM table_name)
CONNECT BY LEVEL <= mx + 1)
WHERE lvl - 1 <= LENGTH (REPLACE ( col2, ',',''));Max -
Better approach for checking column values between two different rows
My requirement is to find best Approach to find difference between column values of two different rows.Below I've mentioned two different
approaches I'm thinking of,but I'd like to know is there any other better approach.
version details
SQL> SELECT *
2 FROM V$VERSION;
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for Solaris: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - ProductionTable creation script
CREATE TABLE R_DUMMY
(CA_ID VARCHAR2(16) NOT NULL ENABLE,
CA_VER_NUM NUMBER(4,2) NOT NULL ENABLE,
BRWR_SHORT_NAME VARCHAR2(25 CHAR),
sic_code number,
FAC_ID VARCHAR2(10) NOT NULL ENABLE
/ insert script
insert into r_dummy (CA_ID, CA_VER_NUM, BRWR_SHORT_NAME, sic_code, FAC_ID)
values ('CA2001/11/0002', 2.00, 'Nandu',1234, 'FA000008');
insert into r_dummy (CA_ID, CA_VER_NUM, BRWR_SHORT_NAME, sic_code, FAC_ID)
values ('CA2001/11/0002', 3.00, 'SHIJU',456, 'FA000008');Desired O/P :
ca_id fac_id column_name previous name after_modification
CA2001/11/0002 FA000008 BRWR_SHORT_NAME Nandu SHIJU
CA2001/11/0002 FA000008 sic_code 1234 456My approach
select ca_id,fac_id,column_name,
decode(column_name,'BRWR_SHORT_NAME',lg_brwr,lg_sic) previous_name ,
decode(column_name,'BRWR_SHORT_NAME',ld_brwr,ld_sic) after_modification
from
select
case
when ld_brwr != lg_brwr then
'BRWR_SHORT_NAME'
when ld_brwr != lg_brwr then
'sic_code'
end
) column_name,ca_id,fac_id,lg_brwr,ld_brwr,ld_sic,lg_sic
from (
select ca_id,fac_id,lag_brwr,ld_brwr,ld_sic,lag_sic
from
Select lead(brwr_short_name,1) over(partition by ca_id,fac_id) ld_brwr,
lag(brwr_short_name,1) over(partition by ca_id,fac_id) lg_brwr,
lead(sic_code,1) over(partition by ca_id,fac_id) ld_sic,
lag(sic_code,1) over(partition by ca_id,fac_id) lg_sic,
ca_id,fac_id
from r_dummy
where (ld_brwr != lg_brwr or ld_sic != lg_sic)
)2nd Approach :
=============
select ca_id,fac_id,column_name,
decode(column_name,'BRWR_SHORT_NAME',lg_brwr,lg_sic) previous_name ,
decode(column_name,'BRWR_SHORT_NAME',ld_brwr,ld_sic) after_modification
from
select
case
when ld_brwr != lg_brwr then
'BRWR_SHORT_NAME'
when ld_brwr != lg_brwr then
'sic_code'
end
) column_name,ca_id,fac_id,lg_brwr,ld_brwr,ld_sic,lg_sic
from (
select ca_id,fac_id,brwr_short_name,sic_code
from
Select ca_id,fac_id,brwr_short_name lg_brwr,sic_code lg_sic
from r_dummy
where ca_ver_num = '2.00'
)o,(
Select ca_id,fac_id,brwr_short_name ld_brwr,sic_code ld_sic
from r_dummy
where ca_ver_num = '3.00'
)n
where 0.ca_id = n.ca_id
and 0.fac_id = n.fac_id
and (ld_brwr != lg_brwr or ld_sic != lg_sic)
)Hi Experts,
I've provided sample data where I'm checking for just two columns viz brwr_short_name ,sic_code,but in real time
I've to check for 8 more columns so please suggest me with a better approach.
I appreciate your precious suggestions.Hi,
Thanks for posting the CREATE TABLE and INSERT statements; that really helps!
Here's one wa. Like your 2nd approach, this uses a self-join:
WITH got_r_num AS
SELECT ca_id
, ROW_NUMBER () OVER ( PARTITION BY ca_id
, fac_id
ORDER BY ca_ver_num
) AS r_num
, brwr_short_name
, TO_CHAR (sic_code) AS sic_code
, fac_id
-- , ... -- Other columns (using TO_CHAR if needed)
FROM r_dummy
, unpivoted_data AS
SELECT *
FROM got_r_num
UNPIVOT INCLUDE NULLS
( txt
FOR column_name IN ( brwr_short_name AS 'BRWR_SHORT_NAME'
, sic_code AS 'SIC_CODE'
-- , ... -- Other columns
SELECT p.ca_id
, p.fac_id
, p.column_name
, p.txt AS previous_name
, a.txt AS after_modification
FROM unpivoted_data p
JOIN unpivoted_data a ON p.ca_id = a.ca_id
AND p.fac_id = a.fac_id
AND p.column_name = a.column_name
AND p.r_num = a.r_num - 1
AND p.txt || 'X' != a.txt || 'X'
ORDER BY a.r_num
;To include other columns, add them in the 2 places where I put the comment "Other columns".
Ca_ver_num can have any values, not just 2.00 and 3.00.
This will show cases where a value in one of the columns changed to NULL, or where NULL changed to a value.
There ought to be a way to do this without a separate sub-query like got_r_num. According to the SQL Language manual, you can put expressions in the UPIVOT ... IN list, but when I tried
... UNPIVOT INCLUDE NULLS
( txt
FOR column_name IN ( brwr_short_name AS 'BRWR_SHORT_NAME'
, TO_CHAR (sic_code) AS 'SIC_CODE'
)I got the error "ORA_00917: missing comma" right after TO_CHAR. Perhaps someone else can show how to eliminate one of the sub-queries. -
Insert data into the column which is having null values.
Hi,
I have a column called "Classification_CD" .This column is having NULL values.I want to insert the data into this column.
I tried to write the query as follows. But it is showing the mesg error "SQL Error: ORA-01400 cannot insert NULL into ("ABC"."A_CMP_W"."A_CMP_SEQ_NUM")"
Can any one please help me out to write query to insert the dat afor this.
Thanks.I think you are taking about updating the null value.So you can do this..
SQL> select * from table_a;
ID SCHEDULED MARK PRID
5 07-NOV-10 T05 7
6 18-SEP-10 T06 8
4 31-JAN-11 T02 2
1 18-JAN-11 T01 2
2 18-JAN-11 T02
3 18-JAN-11 T03 1
6 rows selected.See that prid is Null for id 2
SQL> update table_a
2 set prid =10
3 where id =2;
1 row updated.
SQL> commit;
Commit complete.
SQL> select * from table_a;
ID SCHEDULED MARK PRID
5 07-NOV-10 T05 7
6 18-SEP-10 T06 8
4 31-JAN-11 T02 2
1 18-JAN-11 T01 2
2 18-JAN-11 T02 10
3 18-JAN-11 T03 1
6 rows selected.
SQL> But remember while updating u should choose a primary key column in
where condition so that only desired row or record is updated..
Regards
Umesh -
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 -
Get the minimum value from a cursor
Hi,
i have a cursor that returns the following two columns in a stored procedure. now i want to find the minimum value of SORT NUMBER column .
Can anybody give me an idea.....
create or replace procedure get_min
as
cursor c1 is
select group_number
, sort_number
from group_table
v_min number;
begin
for c1_rec in c1
select min(c1_rec.sort_number) into v_min ;
end;
GRP_NUMBER SORT NUMBER
1001 9978
1002 9979
1003 9946 thanks in advance.OPTION1
I'm guessing your stored procedure loops through the cursor (goes record by record and does something), correct? If it loops through all records, then
1. first define variable which will hold minimum value e.g.
my_min_value number := 0;
2. then add this inside the loop (as you loop through all records, my_min_value will get assign the lowest value)
my_min_value := LEAST(my_min_value, c1_rec.sort_number);
when the cursor is done looping through all records, you get your minimum value
small note: make sure c1_rec.sort_number is not null or you know how null works with least function
OPTION2
if you don't loop through all records (maybe have a condition and stop looping), then you can always change the SQL and add the minimum value to the SQL, there are multiple ways to do this, this is one of them - I hope there is no typo - it's 8pm :-)
select group_number
, sort_number,
min(sort_number) OVER ( )
from group_table
OPTION3
get rid of cursor, there are probably 5000 better choices :-)
Maybe you are looking for
-
Can anyone suggest a simple system for backing up my MacBook?
I have a MacBook 120G which runs Tiger. I also have an Aiport Extreme, which is connected to a printer via USB. I want to buy an external hard drive to create a safety back up of my whole system. I have been trawling the suppliers' websites, getting
-
Query Variable Selection Creation
HI we have a req to select 600 material numbers in a query through the variable screen, but the users cant select 600 variables every time, RIGHT.... so we are trying to brianstorm on a work around, if you have worked on an instance like this please
-
802.1x Windows XP Supplicant
Hello, I have been recently trying to get the built in Windows XP supplicant to function in the following way: using EAPOL-MSCHAPv2 with Username/Password/Domain credentials at the Windows login screen. No certificates, just a pre-shared key between
-
HT1937 iphone 3GS carrier always says no service and can't activating
my iphone 3GS always shows no service each time i use a card. i have just upgrade ios 6.0 and iwant to activate it but because of the sim card i can't activate my iphone 3GS. can anyone help me? everything is accepted...
-
Import mail from deleted user account
I created a new administrator account on my mac mini and deleted the old one but chose to retain all of the user folders and files. I would like to go back and import mail messages from a pop mail account in the deleted user library, but can not navi