Update a row based on the minimum value
I need to update a row value in a table (table1) which is having one-to-may relationship with another table (table2) based on priority. Below is the table structure and sample data. I have a merge statement which can just do this, but it's taking too much to execute if the data in table2 is huge.
I want to reduce the execution time, can anyone suggest me another way to do this.
--Table Definition
CREATE TABLE TABLE_1 (ENAME VARCHAR2(20), ID NUMBER(20), DISPLAY_NAME VARCHAR2(20), PRIMARY KEY (ENAME));
CREATE TABLE TABLE_2 (ENAME VARCHAR2(20), DISPLAY_NAME VARCHAR2(20), PRIORITY NUMBER(1));
--Sample data
INSERT INTO TABLE_1 (ENAME,ID) VALUES ('EMP1','1000');
INSERT INTO TABLE_1 (ENAME,ID) VALUES ('EMP2','2000');
INSERT INTO TABLE_2 (ENAME,DISPLAY_NAME,PRIORITY) VALUES ('EMP1','APPLE',1);
INSERT INTO TABLE_2 (ENAME,DISPLAY_NAME,PRIORITY) VALUES ('EMP1','DELL',2);
INSERT INTO TABLE_2 (ENAME,DISPLAY_NAME,PRIORITY) VALUES ('EMP1','MS',NULL);
--Merge to perfor the update
MERGE INTO TABLE_1 T USING
(select ename, display_name from TABLE_2 where (ename,priority) in (
select distinct ename, min(priority) over (partition by ename) from TABLE_2 min_prior)) Q
ON (T.ENAME = Q.ENAME)
WHEN MATCHED THEN UPDATE SET DISPLAY_NAME = Q.DISPLAY_NAME;
Hi,
You can use the aggregate FIRST function, like this:
MERGE INTO table_1 t
USING (
SELECT ename
, MIN (display_name) KEEP (DENSE_RANK FIRST ORDER BY priority)
AS first_display_name
FROM table_2
GROUP BY ename
) q
ON (t.ename = q.ename)
WHEN MATCHED THEN UPDATE
SET t.display_name = q.first_display_name
;If the combination (ename, priority) is not unique in table_2, then this uses the first display_name (in normal sort order) among those with the lowest priority. This probably can't happen, becuase your original statement would raise an error if it did.
For performance problems, see the forum FAQ {message:id=9360003}
Similar Messages
-
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> -
Changing the font color for the complete row based on the Keyfigure Values
Hi Experts,
Can any one help me to find a solution for this?.
I have a requirement, in which the Font color for the complete Row needs to be set to RED in Bex Report, when the corresponding Row Keyfigure is more than a particular value.
Ex: Notification-Material-Customer-Def Qty-delivered Qty
1000000 - XXXXX- AAAAAA-10-1000
in the above example, when the Defect qty increses more than 10, then the complete Row Including the characterstics, Notification, Material, and customer Should be Highlighted in Red. This has to happen automatically once the Query is refreshed.
Please let me know if you have any suggestion here?.
Regard,
Muruganand.KHi,
Step 1: Click the Format Menu in Excel(BEX Analyzer)
Step 2: Click the Style submenu
Step 3: there will be number of SAPBEX formats available. Each of these relates to another cell of BEx (Header, Cell Data,
Result Row, Hierarchies, etc.). Also, they depend on data types.
Step 4: Select SAPBEXchatext
Step 5: Click Modify. This displays all the standard formatting option as shown below.
Step 6: Select Font, Color (Background/ Font).
Step 7: Click OK on both the screens. The entire BEx output result row Font and color is modified.
Hope it helps........
Regards,
Suman -
Count the number of rows based on the values!!!
Hi all,
What I am using:
I am working with a multidimensional database in Visual Studio 2010 using its Data source view and calculation member and dimension usage.
What I want to do:
I have a fact table that has five columns(leg(s),hand(s), Head and body,overall) that shows the category of how severe the injury is. Let say for the records all columns never have an empty value(no injury is stated with 'No injury' ) . These five columns
are connected with a dimension that has all the available values (Category A-E of injury).The overall has the most severe from the other four columns. I want to create a bar chart with five different measure
values, one for each column, and count the values in those columns.
For example : I have a slicer in the excel and a bar chart and the slicer has all the values of the Category of the injury ( Cat a,Cat B, Cat C, ... Cat E, No injury ) and when i select one of them, lets say
Cat C, the bar chart should update and show how many Cat C each measurement column has.
Example FACT table:
ID LEG HAND HEAD BODY OVERALL
1 No A No No A
2 No D C C C
3 E C D A A
4 E E B C B
So if i selected C the bar chart will count (Leg = 0, Hand = 1, Head = 1, body = 2 and Overall = 1).
Any ideas ?
Thanks for the help and the time :)Hi DBtheoN,
According to your description, you want to create a chart on excel worksheet to count the rows based on the value, right? If in this case, I am afraid this issue is related to Office forum, I am not the expert of Office, you can post the issue on the corresponding
forum.
However, this requirement can be done easily on SQL Server Reporting Services. You can using the expression below to count the rows.
=COUNT(IIF(Fields!LEG.Value=Parameters!TYPE.Value,1,NOTHING))
Regards,
Charlie Liao
TechNet Community Support -
How can I select and delete rows based on the value in one column?
I searched through the discussion board, and found a thread on deleting blank rows, but not sure how to modify it to work with my issue.
I have put together a rather complicated spreadsheet for designing control systems, it calculates parts needed based on check boxes selected in a second spreadsheet.
Since not all systems require all parts there are many rows that have a 0 quantity value, I would like to select these rows and delete them once I have gone through the design phase (checking off required features on a separate sheet).
I like the way the other thread I found will gather all the blank rows at the bottom without changing the order of the rows with data in them.
I don't understand exactly how the formula in the other thread works well enough to modify it to look for a certain column.
I hope I made myself clear enough here, to recap, I would like to sort the rows based on a zero value in one (quantity) column, move them (the zero quantity rows) to the bottom of the sheet, and then delete the rows with a zero quantity (I can delete them manually, but would like to automate the sorting part).
Thanks for any help anyone can provide here.
DannyI apologize but, as far as I know, Numbers wasn't designed by Ian Flemming.
There is no "this column will be auto-destructing after two minutes"
You will have to use your fingers to delete it.
I wish to add a last comment :
if your boss has the bad habit to look over your shoulder, it's time to find an other one.
As I am really pig headed, it's what I did. I became my own boss so nobody looked over my shoulder.
Yvan KOENIG (VALLAURIS, France) mercredi 13 juillet 2011 20:30:25
iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8
Please : Search for questions similar to your own before submitting them to the community
To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer ! -
Formating the Row Based on one column value
Hi Friends
I am trying to format the Entire row based on the value of the first column in my Answers.
Example if first column value in 'F' now i want the Entire row to be colored
I can do conditional formating on one column but i want to do it on the entire row
F 8.1 % 12.0 %
E 5.2 % 3.5 %
M 2.3 % 3.3 %
If any one has done this or any suggestions please respond
Thanks
SangIts a Pivot View
F 8.1 % 12.0 %
E 5.2 % 3.5 %
M 2.3 % 3.3 %
the column 1 --> F,E,M are the Product
the column 2 --> 8.1% , 5.2% , 2.3% are the sales in year 2008
the column 3 --> 12.0 % , 3.5 %, 3.3 % are the sales in year 2009
So will i be able to apply the formating in pivot view based on one column to other column If yes please let me know how or
suggest if this can be done using the BI Office , or BI publisher
sing the BI Office i can do the formating in Excel but once i refresh the data all the formating is gone ... :(
I am donno BI Publisher if we have to use BIP please suggest any solution its very very very urgent and important report formating they need here ....
Thanks in advance David
sango -
Is there a way to hide some reports based on the selected values in prompt.
Hi Experts,
Is there a way to hide some reports based on the selected values in prompt.
For ex. if a year is selected in the prompt then the report should display year wise report.
If a year and half year both are selected in the drop down from prompt section then 2 reports should come.. One for year wise and another for half year wise.Kindly look into this.
Regards
AshishHi,
Use presentation values in prompts for year,half,qtr and month.Example- For year-y is presentation variable in the same way for halfyear-h,qtr-q and month-m.
create four intermediate reports.Example-Report r1 with only year column,r2 with only halfyear column,r3 with qtr column and r4 with month column.
Make column in each report(r1,r2,r3,r4) is equal to their presentation variables(y,h,q,m).
Use four sections.
Section1-Place report that should come when only year.
section2-Place report that should come for year and halfyear.
Section3-Place report that should come for year,halfyear and qtr.
Section4-Place report that should come for year,halfyear,qtr and month.
Apply guided navigation for each section selecting guided navigation-
For section1-
properties->Guided navigation->check this Reference Source Request(Yes)->select report r1(year)->check this Show Section(if request returns row)
In the same way do for remaining section2(select r2),section3(select r3) and section4(select r4)
Thanks,
Srikanth
http://bintelligencegroup.wordpress.com/ -
Hello Everyone
I have two drop downs. Both are coming from look up fields from two lists. i want to set a default value(first list item) for the first drop down list box and then apply cascading based on the default value for the next drop down list box. I found one article(http://www.bizsupportonline.net/infopath2010/display-first-item-drop-down-list-box-infopath-2010.htm)
where in i can set a default value but i can't apply cascading based on that default value. Any suggestions would be highly appreciated.
Thanks
Ramanjulu Naidu NHey Ramanjulu,
Take a look at the below article which I believe will answer your question.
http://basquang.wordpress.com/2010/03/29/cascading-drop-down-list-in-sharepoint-2010-using-infopath-2010/
Daniel Christian (MCTS) -
How to find bpel instance in 11g based on the index values using Java APIs
Hi ,
In SOA10G we had option to find the instances based on the index value using Java APIs like below.
WhereCondition criteria= new WhereCondition(SQLDefs.CX_index_1 + " = ?");
criteria.setString(1, "indexValue");
Locator mLoc = getLocator();
IInstanceHandle[] foundInstances = mLoc.listInstancesByIndex(criteria);
Please tell me how to achieve the same functionality in SOA 11G using Java APIs
Regards,
SabaI have multiple bpel in my composite. I checked in ci_indexes table and it shows the instance number of the bpel process. But the em console is showing only the composite instance number. when I opened composite instance, I could see all the bpel process with instance number in the audit trail. How can I find the the actual composite instance number that I should search for in the em console ???
-
Freight Calculation based on the net value of the Line item
Hi SAP Gurus,
I have one requirement for Freight calculation(Sales order is created through an IDOC) :
In the idoc,we will receive a freight dollar amount - which will be the total amount of freight.(example 100)
We will also receive sales dollar for each line item ,which is then passed to the pricing procedure, for a total amount of sales for that Sales order.
(examples below, for a total of 1500)
The 100 is to be posted to a freight G/L account.
The 100 is further divided by each profit center of the materials on the Sales order.
The freight is split out amongst the profit center , based on the net value of the line item.
Freight value to be allocated = Line item value/total value of the sales order * Freight amount.
Total of the sales order =1500
Line item value Freight value calculation Profit center
Material A: 800 800/1500*100 = 53 Profit center A
Material B: 500 500/1500*100 = 33 Profit center B
Material C: 200 200/1500*100 = 13 Profit center C
Please let me know how to achieve this functionality in pricing procedure or what changes i need to make in Freight condition type.
Thanks in advance,
Bhakar SahaWere you able to resolve this issue of allocating freight costs to line items/profit centers using the net value of the line items?
-
Dist. of Header Condition based on the material Value
Hi All,
I have one query regarding the header Condition.i have selected the Calculation type as B - fixed amount (mandatory) for a particular Condition type and also selected the header and Item condition indicator.Now if the material have more than one line item then the system distributes this condition based on the quantities in PO.
My client requirement is that they want to have a header condition as we are using now. But they want to distribute this header condition according to the material values for each line items in a PO. please Mention that this condition is a fixed value (mandatory).
So, how can we make a Fixed Value (Calculation type) for a header condition to be distributed among the line items based on the base Value?
Please revert back asap.
Sure, points will be awarded for the same.as explained earlier ,
system is distributes the header amount on the basic of value calculated by Basic X qty
e.g.
header value =100
two line item
1 is with Rs 4/- and qty is 10
2 is with Rs 10/- and qty is 15
so distribution is
Rs 21.05/- for 1st item
and
Rs 78.94/- for 2ed item
regards,
sujit -
Setting the series color of a bi beans graph based on the data values
How do I conditionally set the series color of a bi beans graph based on the data values?
I am using the following code to get the data values and set the series color:
Graph gr=(Graph)CmdrDashboardP1_pres1.getView();
DataAccess da=gr.getGraphModel().getDataAccess();
DataDirector dd=gr.getDataDirector();
DataMap dm=dd.getDataMap();
int re=dd.ROW_EDGE;
int ce=dd.COLUMN_EDGE;
Object val=da.getValue(re,ce,dm.DATA_TYPE);
int seriesCount=da.getEdgeCurrentSlice(DataDirector.ROW_EDGE);
if (val <=45.0)
gr.getSeries().setColor(new Color(255,0,0),seriesCount);
I get a NullPointerException from the line of code "Object val=da.getValue(re,ce,dm.DATA_TYPE)." I have tried the code with DATA_UNFORMATTED as well, but get the same exception. When I print the DataMap value of dm the results are [dataUnformatted, dataViewFormat, value, dataIsTotal, dataType].
Also, I get the error "method <= (java.lang.Object,double) not found in class _CmdrDashboardP1" from the "if (val <=45.0)" code.
Thanks for any assistanceHow do I conditionally set the series color of a bi beans graph based on the data values?
I am using the following code to get the data values and set the series color:
Graph gr=(Graph)CmdrDashboardP1_pres1.getView();
DataAccess da=gr.getGraphModel().getDataAccess();
DataDirector dd=gr.getDataDirector();
DataMap dm=dd.getDataMap();
int re=dd.ROW_EDGE;
int ce=dd.COLUMN_EDGE;
Object val=da.getValue(re,ce,dm.DATA_TYPE);
int seriesCount=da.getEdgeCurrentSlice(DataDirector.ROW_EDGE);
if (val <=45.0)
gr.getSeries().setColor(new Color(255,0,0),seriesCount);
I get a NullPointerException from the line of code "Object val=da.getValue(re,ce,dm.DATA_TYPE)." I have tried the code with DATA_UNFORMATTED as well, but get the same exception. When I print the DataMap value of dm the results are [dataUnformatted, dataViewFormat, value, dataIsTotal, dataType].
Also, I get the error "method <= (java.lang.Object,double) not found in class _CmdrDashboardP1" from the "if (val <=45.0)" code.
Thanks for any assistance -
How to increase the salary based on the percentage value
Hi All,
Could you please let me know which API need to be used to implement the hike in salary based on the percentage value. And what all the parameters to be used.
Appreciate your help...
Thanks...Dear All,
Any luck on this please?
thanks.. -
using Shading Dictionary to perform shading in pdf,before that the shading dictionary call from Pattern Dictionary.In the Pattern Dictionary there is an Matrix based on the matrix value location the shading operation is perform,So i dont know how to calculate value of pattern Dictionary matrix value.
10 0 obj
<< /Type /Pattern
/PatternType 2
/Shading 11 0 R
/Matrix [1.00 .00 .00 1.00 54.00 53.00] // the matrix value how to calculate
>>
11 0 obj
<<
/ColorSpace /DeviceRGB
/Function 12 0 R
/ShadingType 2
/Coords [109.2726 69.00 109.2726 .00]
/Extend [true true]
>>
12 0 obj
<<
/FunctionType 0
/Domain [.00 1.00]
/Range [.00 1.00 .00 1.00 .00 1.00]
/Size [1002]
/BitsPerSample 8
/Length 3006
>>
stream
here is an stream of colors
endstream
endobj
Can anybody help me please.
Regards, Sasi kumar sekar.Hi, Sasi -
The Matrix maps coordinates in your shading dictionary into User Space. That is, the Matrix entry in the Pattern dictionary specifies a coordinate transformation that will be applied to coordinates specified in the shading dictionary.
To take your example, you have an axial shading extending from (rounding off) 109,69 to 109,0. Your Pattern dictionary specifies the Matrix
[ 1 0 0 1 54 53 ]
This transformation matrix corresponds to a scale of 1,1 (that is, no change in scale) and a translation of 54,53. Thus, the actual endpoints for the axial shading will be the User Space positions 163,122 and 163,53 (assuming I’ve added correctly).
As to what values to use for your Matrix, it depends on how you’ve set up your Shading dictionary. If the coordinates you’ve specified are actually where you want the gradient to go, then just use an identity matrix
[ 1 0 0 1 0 0 ]
By the way, are you sure that the Pattern dictionary includes a Matrix entry? I seem to remember (it's been a while since I've looked at Patterns) that the matrix is supplied as an argument to the makepattern operator:
<<patternDict>> [ 1 0 0 1 0 0 ] makepattern
Hope that helps.
- John Deubert
Acumen Training
PostScript and PDF
Training & Consulting -
How to find bpel instance in 11g based on the index values
We have 10g BPEL process where we define 4 index values for all the instances. Whenever support request comes, we ask index values and based on that we search the process instance.
We have migrated this 10g bpel process to 11g now. How to find bpel instance in 11g based on the index values ???I have multiple bpel in my composite. I checked in ci_indexes table and it shows the instance number of the bpel process. But the em console is showing only the composite instance number. when I opened composite instance, I could see all the bpel process with instance number in the audit trail. How can I find the the actual composite instance number that I should search for in the em console ???
Maybe you are looking for
-
Going to the LastPage of a report takes too long
<p>Hi,</p><p>Using Web ReportViewer. Pressing the LastPage button in the browser's window takes LONG time before the last page appears (and almost 100% CPU), as the CR control apparently generates the complete document internally, before showing its
-
I ran ios6 updates on my ipad and iphone, not knowing that using the icloud and sharing an itunes account with my daughter, would have our phones and my ipad now linked together. My contacts are gone (875 of them) and I have her contacts, and our te
-
Wireless USB hook-up need driver??
I have a powermac g4. I have purchased D-Link wireless router on my pc downstairs, I then have the USB card for my mac upstairs, but it is acting like I need a driver for my mac in order to get this wireless usb to work. Apple doesn't supply and/or D
-
While reverse Miro document gettin following error ? How do I reveres the document? Balance not zero: 3,359.70 ; debits: 176,907.30 ; credits: 180,267.00 Message no. M8534 Diagnosis The system has discovered a difference between the debits and credi
-
Query in Discovery Server!!!!
Hi all, Can anyone please tell me if there is any website / link where we can have a demo / test run of Discovery server. Kindly reply as fast as possible as this is bit urgent. Regards, Vijay