Query to find the setting and add it to the minimum value
Hi, I need a query to run under operationI have a table as shown below
chg tax code Bill rec_no r_cost d_cost
12345 1 114,35 100.30 1.00 1.00 234
2 12345 114,35 2.00 1.00 1.00 201
3 12345 114,35 14.00 1.00 1.00 600
4 23412 120.90 110,40 1.00 1.05 700
5 23412 120.90 12,50 1.00 1.05 900
In this table, I need to find the setting for each rec_no as
(r_cost + chg + taxes)-sum (d_cost) for rec_no = 12345
(114.35 + 1.00 1.00)-(100.30+2.00+14.00) plus 0.05
This 0.05 must be added to the minimum (code) for the rec_no 12345.
If the d_cost of the code, with rec_no = 12345 201 should be (2.00 + 0.05 = 2.05).
and,
(120.90 + 1.00 1.05)-(110.40+12.50) plus 0.05
This 0.05 must be added to the minimum (code) for the rec_no 23412.
If the d_cost of the code, with rec_no = 23412 700 should be (110,40 + 0.05 = 110.45).
Kindly help me in writing of an oracle application to perform the above operation.
with tab as (
select 1 invoice,12345 rec_no,114.35 r_cost,100.30 d_cost,1.00 chg,1.00 tax,234 code from dual union all
select 2 invoice,12345 rec_no,114.35 r_cost,2.00 d_cost,1.00 chg,1.00 tax,201 code from dual union all
select 3 invoice,12345 rec_no,114.35 r_cost,14.00 d_cost,1.00 chg,1.00 tax,600 code from dual union all
select 4 invoice,23412 rec_no,120.90 r_cost,110.40 d_cost,1.00 chg,1.05 tax,700 code from dual union all
select 5 invoice,23412 rec_no,120.90 r_cost,12.50 d_cost,1.00 chg,1.05 tax,900 code from dual
)
SELECT tab.*,
CASE
WHEN DENSE_RANK() OVER (partition BY rec_no ORDER BY code)=1
THEN r_cost + chg +tax-SUM(d_cost) over (partition BY rec_no)+MIN(d_cost) keep (DENSE_RANK FIRST
ORDER BY code) over (partition BY rec_no)
ELSE d_cost
END adj
FROM tab
ORDER BY invoice
Find out what...
Ravi Kumar
Tags: Database
Similar Questions
-
PL/SQL loop to find the minimum value
I want to find the minimum value from a table using the pl/sql loop
I have data format below.
1 ABC 2
1 ABC 20
1 ABC 500
1 ABC 2000
XYZ 2 250
JKL 3 300
MNP 3 350
3 KLM 400
I wrote the code below. His does not work. Please suggest.
Set serveroutput on
declare
x number: = 3;
y VARCHAR2 (3): = 'ABC ';
fmin number: = 0;
number of Fmax: = 0;
Start
for rec in (select sal from test
where id = name and x = y) loop
If rec.sal > fmin then
fmin: = rec.sal;
on the other
FMAX: = rec.sal;
fmin: = fmax.
end if;
end loop;
dbms_output.put_line (Fmax);
end;
/I want to output 2 on top of code.
Thanks in advance
Why PL/SQL? SELECT MIN (SAL) OF TEST will be more rapid and much less coding. In any case:
declare
number of v_min_sal;
Start
for v_rec in a loop (select sal from emp)
If nvl (v_min_sal, v_rec.sal + 1) > v_rec.sal
then
v_min_sal: = v_rec.sal;
end if;
end loop;
dbms_output.put_line (' lowest salaray is "' |") v_min_sal | '"');
end;
/
The lowest Salaray is "800".
PL/SQL procedure successfully completed.
SQL >
SY.
-
SQL - find the minimum value for each separate record...
Hi all
I have a table like this in SQL Server
Date of sale of product
A date
A date
A date
B date of
B date of
C date
C date
C date
I would like to write a query to find the minimum date (i.e. the date
the first sale) for each product
Thus, the expected results would be
Date of sale of product
A date min
B date of min
C date of min
How can I do this using SQL Server?
any help is greatly appreciated!
Thank you!
Product SELECTION, MIN (sale_date)
From your_table
GROUP BY productEtienne
-
Find the minimum value of the table in time...
Firstly that it is not "find the min value in the table.
It is:
I have a table that changes its values at each iteration, and I want to compare the new values with previous values and make a new array with the minimum values...
In C++, it would be like this:
int main() {}
int array [8];
int min [8];
int i;
for (i = 0; i<>
min [i] = 1000000; Initialize minimum table with a high value
}
{while (1)}
Array = update_array ();
for (i = 0; i<>
If (array [i]<>
min [i] = array [i];
}
}
do things...
}
return 0;
}
IM new to labview and it always confuses me a lot...
Thanks in advance.
Using the function Max & Min regular (not table Max & min as you know) with tables and a good will of employment registry change. Max Min &, as most of the digital functions, is polymorphic and works witt tables as well as scalars.
Lynn
-
Query to find the 2 values in column 1
Hello
I have a table like
The user enters 2 values, for example A10Q and A10R. I don't need only the records that have the two values.create table table1 (col1 NUMBER, col2 VARCHAR2(4), col3 varchar2(4)); Sample Data: select COL1, NVL(COL2,'---') col2, NVL(COL3,'---') col3 from table1; COL1 COL2 COL3 ---------------------- ---- ---- 10 A10Q --- 10 A10R --- 20 --- A10Q 20 --- A10R 30 A10Q --- 30 A10R --- 30 --- A10Q 30 --- A10R 40 A10Q --- 40 --- A10R 50 A10Q --- 11 rows selected
So I need lines of the sample of data where COL1 = 10,20,30 and 40. 50 must be returned as it has only A10Q and not A10R.
I just need COL1 values.
I wrote the query below, but wanted to know if there is a better way to write this
Kind regardsselect * from table1 where col1 in (select col1 from table1 where (col2 = 'A10Q' or col3 = 'A10Q')) and (col2 = 'A10R' or col3 = 'A10R'); COL1 COL2 COL3 ---------------------- ---- ---- 10 A10R 20 A10R 30 A10R 30 A10R 40 A10R
VikramAssuming that the values cannot be duplicated for any group of individuals col1, something like that maybe...
select col1 from table1 where 'A10Q' in coalesce(col2, col3) or 'A10R' in coalesce(col2, col3) group by col1 having count(*) = 2
(not tested as you did not provide the data in a usable format)
-
Query to find the distinct values
Hi all
Given, it's like
with t as (select 1 eno, "AC_ACCOUNT" the double job_id)
Union select 2 eno, 'AC_ACCOUNT' job_id of the double
Union select 3 eno, 'AC_ACCOUNT' job_id of the double
Union select 4 eno, 'AC_MGR' job_id of the double
Union select 5 eno, 'AD_VP' job_id of the double
Union select 6 eno, 'AC_MGR' job_id of the double
Union select 7 eno, 'AC_MGR' job_id of the double
Union select 8 eno, "FI_ACCOUNT" double job_id)
Select * from t;
It takes the job_id not duplicated output.
For this release of data should be,
AD_VP
FI_ACCOUNT
Is it possible to write a query without hard coding or using separate?
Kind regards
SoundariyaKumar.R
Hello
You could do like:
SQL >
SQL > with t as (select 1 eno, "AC_ACCOUNT" the double job_id)
2 union select 2 eno, "AC_ACCOUNT" double job_id
3 union select 3 eno, "AC_ACCOUNT" double job_id
4 union select 4 eno, "AC_MGR" double job_id
5 union select 5 eno, "AD_VP" double job_id
6 union select 6 eno, "AC_MGR" double job_id
7 union select 7 eno, "AC_MGR" double job_id
8 union select 8 eno, "FI_ACCOUNT" double job_id)
9 select job_id from group by job_id t having count ()) = 1;
JOB_ID
----------
AD_VP
FI_ACCOUNT
SQL >
-
Find the minimum value in digital array that is greater than 0
So far I have;
$pfpp = min ($pflist);
$pflist is the array of digital values and contains about 0.
I need to change to $pfpp = min ($pflist); to return the lowest number which is greater than zero.
I am stuck, can anyone help?
Thank you
Change the values in the table so I can't sort them in ascending order.
Of course you can. Or you can copy the table into a temporary array.
$temp = $pflist;
sort ($temp, SORT_NUMERIC)
foreach ($temp as $value) {}
If $value > 0; $number = $value; break;
}
echo "entry of zero smaller in pflist is $number";
-
Hello
SQL query to find the total number of source based nonsource passangersbetween source and destination station and passenger station on the same chekindate.
Please help on this script and let me know if you need more details.
---
You use a SELECT statement. Let me know if you need more details.
-
Query to find the Pages and the list of permissions associated with a particular role in PS
I want a query to find the Pages and the list of permissions associated with specific roles in PS.
For example, if we see the role of manager accounts payable, it conatins Pages and the list of permissions.
But, to get everything in EXCEL sheet by Manuel priocess's BIG job. So, can someone give me the query.
Please try under queries
The roles assigned to the list of Perm:
SELECT B.ROLENAME
OF PSCLASSDEFN A, PSROLECLASS B
WHERE (A.CLASSID = B.CLASSID
AND A.CLASSID =: 1).
List of Perm pages can access:
SELECT B.MENUNAME, B.BARNAME, B.BARITEMNAME, B.PNLITEMNAME, C.PAGEACCESSDESCR, B.DISPLAYONLY
OF PSCLASSDEFN A, PSAUTHITEM B, PSPGEACCESSDESC C
WHERE (A.CLASSID = B.CLASSID
AND A.CLASSID =: 1
AND B.BARITEMNAME > ' '
AND B.AUTHORIZEDACTIONS = C.AUTHORIZEDACTIONS)
-
query to find the dependent task, attached to the task on a response in OIM 11 g
can someone help me to do a sql query to find the dependent task, attached to the task on a response in OIM 11 g
Published by: user13331347 on Sep 3, 2012 14:09Use under query to find the dependent task in OIM 11 g: -.
Select pkg.pkg_name, mil.mil_name, rsc.rsc_data, rsc.sta_key, sta.sta_status, sta.sta_bucket, mil2.mil_name
pkg pkg, tos tos, mil mil, mil mil2, rsc rsc, sta sta, rgm the rgm
where pkg.pkg_key = tos.pkg_key
and tos.tos_key = mil.tos_key
and mil.mil_key = rsc.mil_key
and rsc.sta_key = sta.sta_key
and rgm.rsc_key = rsc.rsc_key
and rgm.mil_key = mil2.mil_key
order of pkg.pkg_name, mil.mil_name, rsc.rsc_data, sta.sta_status, mil2.mil_name -
Query to find the coordinates of employee salary
Hello
Could someone help write the query to find the salary of the employee details.
Thanks in advance.This should help you get started:
SELECT papf.full_name
papf.email_address
ppp.proposed_salary_n salary
OF per_pay_proposals ppp
per_all_assignments_f ADP
per_all_people_f women's wear
WHERE ppp.assignment_id = paaf.assignment_id
AND paaf.assignment_type = 'E '.
AND paaf.primary_flag = 'Y '.
AND paaf.person_id = papf.person_id
AND nvl (papf.current_employee_flag, 'n') = 'Y '.
AND trunc (sysdate) BETWEEN
PPP.change_date AND ppp.date_to
AND trunc (sysdate) BETWEEN
PAAF.effective_start_date AND paaf.effective_end_date
AND trunc (sysdate) BETWEEN
PAPF.effective_start_date AND papf.effective_end_date; -
What is the query to find the name of all applications for all EBS R12.1.3 modules?
With regard to:
Mr. Shahzad Saleem
Try:
SELECT * FROM fnd_concurrent_programs_vl;
-
Hi team,
I have the following query where I need to find the max value
[code]
with t as)
Select 'L1' R_nm, R_Data 'Data', 'Obj' R_Obj, r_prec 'Wd', '2' double val
Union of all the
Select 'L1', 'Data', 'Obj', 'No', '4' double
Union of all the
Select 'L2', 'Data', 'Obj', 'No', '4' double)
Select t.*, max (val) on rk (partition r_nm, r_data, r_obj) of t
[/ code]
My results should be
[code]
r_nm r_data r_obj r_prec rk val
L1 Data Obj 1 2 Wd
L1 data Obj 4 No.2
L2 Data Yes 1 1 Obj
[/ code]
Thank you
Hello
It seems that you are not interested in the MAX at all. Looks like you want to classify the lines, such as one that has the lowest value is assigned the number 1, the 2nd line with the lowest values gets 2,... and line with him gets N-th lowest value N. If is not serious if the MAX is 4, 2 or 420.
Here's a way to do it:
SELECT T.*
, RANK () OVER (PARTITION BY r_nm, r_obj)
ORDER BY val
) AS rk
T
ORDER BY r_nm, r_obj
val
;
Depending on how you want to deal with links, you can use ROW_NUMBER or DENSE_RANK instead of RANK.
-
Find the minimum date on multiple columns
Hello
I have two questions to find the minimum date on several columns:
1. need a select query that should JOIN two tables and return any information (CASSEDTL) table with minimum date out of DATEISSUED, DATEPLACED, DATEENTERED and STATDATE.
2. need of an update query that should update all cases in the CASEDTL table with the minimum date of DATEISSUED, DATEPLACED, DATEENTERED and STATDATE.
The DDL:
The initial query I have isCREATE TABLE CASEMSTR ( CASENBR NUMBER, DATEISSUED DATE, DATEPLACED DATE, DATEENTERED DATE); CREATE TABLE CASEDTL ( CASENBR NUMBER, STATDATE DATE, RCVDATE DATE, MODDATE DATE); INSERT INTO CASEMSTR VALUES (1, '1 JUL 2007', '1 JUL 2007', '12 JUL 2007'); INSERT INTO CASEMSTR VALUES (2, '1 JAN 2008', '1 JAN 2008', '21 JAN 2008'); INSERT INTO CASEMSTR VALUES (3, NULL, NULL, '3 DEC 2008'); INSERT INTO CASEMSTR VALUES (4, '31 MAR 2009', NULL, '6 APR 2009'); INSERT INTO CASEMSTR VALUES (5, NULL, '22 MAR 2009', '6 APR 2009'); INSERT INTO CASEMSTR VALUES (6, NULL, NULL, '16 JUL 2009'); INSERT INTO CASEMSTR VALUES (7, '1 DEC 2008', '7 DEC 2008', '26 DEC 2008'); INSERT INTO CASEMSTR VALUES (8, NULL, NULL, '17 MAY 2009'); INSERT INTO CASEDTL VALUES (1, '25 JUN 2007', NULL, '2 AUG 2009'); INSERT INTO CASEDTL VALUES (2, '1 JAN 2008', NULL, '2 AUG 2009'); INSERT INTO CASEDTL VALUES (3, '11 NOV 2008', NULL, '2 AUG 2009'); INSERT INTO CASEDTL VALUES (4, '31 MAR 2009', NULL, '2 AUG 2009'); INSERT INTO CASEDTL VALUES (5, '19 JUL 2009', NULL, '2 AUG 2009'); INSERT INTO CASEDTL VALUES (6, '13 JUN 2009', NULL, '16 JUL 2009'); INSERT INTO CASEDTL VALUES (7, '7 DEC 2008', NULL, '16 JUL 2009'); INSERT INTO CASEDTL VALUES (8, '14 MAY 2009', NULL, '16 JUL 2009'); COMMIT;
Need to know what is the best way to complete the new Date of RRS? Receive a new date should be the minimum date of DATEISSUED, DATEPLACED, DATEENTERED and STATDATE. And also how do I write an update statement unique to upade date of receipt in the detail table?SELECT CD.CASENBR, CM.DATEISSUED, CM.DATEPLACED, CM.DATEENTERED, CD.STATDATE, CD.RCVDATE, NULL "NEW RCV DT" FROM CASEDTL CD INNER JOIN CASEMSTR CM ON CD.CASENBR = CM.CASENBR;
Any help would be appreciated! Thanks in advance!Where is the function LESS? Refer to manual SQL.
HTH - Mark D Powell.
put1 > desc multdate Name Null? Type ----------------------------------------- -------- ---------------------------- COL1 DATE COL2 DATE COL3 DATE put1 > select * from multdate; 11-AUG-09 10-AUG-09 01-AUG-09 put1 > select least(col1, col2, col3) from multdate; 01-AUG-09
Published by: MarkDPowell on August 11, 2009 15:53 added example
-
Find the average value of a buffer
Hello
In my VI Panel, I have a digital control, a button and a digital display.
When the user, enter a number in numerical order and press the button, the digital display should show the average value of all the past 5 values entered in the digital control, for example:
1st entry: 10-online average = 10 (as sum = 10)
2nd type: 0-online average = 5 (as sum = 10 + 0 = 10)
3rd enter: 5-online average = 5 (you get the idea...)
4 enter: 1-average online = 4
5 enter: 14-online medium = 6
6 enter: 2-online average = 4.4 (sum = 0 + 5 + 1 + 14 + 2 = 22, because the 1st value is thrown)
How to write this VI?
Thank you!!
You can also use arrays to hold the data in a registry change and find the average value of the last five items.
Good luck
-
Find the minimum distance between two SDO_GEOMETRY in Oracle Spatial?
A circle (SDO_GEOMETRY)
B - polygon (SDO_GEOMETRY)CASE:
B contains A (or)
The Interior of B.How to find the minimum distance between A and B in Oracle Spatial
Hello guuid nameless person.
What is
my_answer := MDSYS.SDO_GEOM.SDO_DISTANCE( my_circle_geometry ,MDSYS.SDO_UTIL.POLYGONTOLINE(my_outer_polygon) ,my_tolerance );
Now, you may need to pay attention to the holes in your polygon, would you the distance and an inner ring if it was closer to you?
If the measure is only to outer rings, so something like
my_answer := MDSYS.SDO_GEOM.SDO_DISTANCE( my_circle_geometry ,MDSYS.SDO_UTIL.POLYGONTOLINE( MDSYS.SDO_UTIL.EXTRACT(my_outer_polygon,1,1) ) ,my_tolerance );
And then also beware of the multipolygons as the foregoing only measured against the first polygon in the MultiPolygon. You need to loop through the polygons of tests just the outer ring in this case.
See you soon,.
Paul
Maybe you are looking for
-
Fake email received? Rescue e-mail address Apple ID
I received an email from the so-called [email protected]. He claims that I recently added my address to e-mail from Apple as a conference entitled "rescue e-mail address for...» [my] AppleID. "I don't have such a thing. Of course the one who sent
-
How to fix the incompatibility of Adobe Flash with Firefox 13.0?
Since 06/10/12, Adobe flash 11.3 wouldn't work in Firefox 13. On any web site. I had no problem with IE. I run Vista, last updated. None of the answers on this site solved my own problems. Here's how I successfully addressed the issue: (1) I removed
-
How to enter the BIOS setup firmly
8.1 - Whenstarting Windows that I'm trying to access the BIOS Setup. I push F2 repeatedlyeven after seizure-Toshiba screen is displayed. Almost always, I get on Windows system, only very few times I get to a tenth of a second at the left bottom of th
-
Time indicated on incoming and outgoing emails not correct with real time sent or received
Time that appears on all my incoming emails indicating when they were sent and the time on my outgoing e-mail is incorrect and does not take account of real time. How can I fix it?
-
Error (disk space low volume C) can anyone HELP?
Hello world! Earlier when I had a problem with virus/malware, I chose to reinstall the operating system from the original installation disc. I use the version of windows 7 Home premium 64-bit with 4 GB of internal memory with a SATA 320 hard drive, w