update of column based on the sum of the data from another table
I have two tables:
Table1 (col1, col2, col3, col4, val1, status) Table2 (col1, col2, col3, col4, val2)
For Table1 and Table2, column (col1, col2, col3, col4) are the primary key of composit.
Table2 could have duplicated lines, that's why I want to group by (col1, col2, col3, col4) and sum (val2)
After that, I want to update Table1.val1 with the value of sum (Table1.val2) where Table1.col1 = Table2.col1 and Table1.col2 = Table2.col2 and Table1.col3 = Table2.col3 and Table1.col4 = Table2.col4 and status = 'V '.
I did something like this:
UPDATE Table1 SET val1 = (
WHERE Table1.col1 = t_sommevbrute.col1 and Table1.col2 = t_sommevbrute.col2 and Table1.col3 = t_sommevbrute.col3 and Table1.col4 = t_sommevbrute.col4)
Could someone help me please? Thank you
merge into table1 t1
using (select col1, col2, col3, col4, sum (val2) val2
from table2
Group
by col1, col2, col3, col4) t2
on (t1.col1 = t2.col1 t1.col2 = t2.col2 and t1.col3 = t2.col3 and t1.col4 = t2.col4 and)
When matched then
update set t1.val1 = t2.val2;
Tags: Database
Similar Questions
-
The default value based on the field from another table to a custom object
I'm trying to set the default value to a field in the custom object to the value of a field of account. I tried the syntax 50 ways different and just don't get the case. The label for the account field displays the form of s/n, the integration of the tag is ltDBA_ACCT and it appears in the fx reports area as Account.Text_22.
The field of custom object that I am triying update is also called s/n, which was originally the required field 'NAME '. The name of the table, account, should it be included? Do I need a function to the field?
I've updated the external ID using the line with syntex < ID > ID (at least higher ID) so I know that it is possible to define a default value, but s / < n >, < ltDBA_ACCT >, 'account '. "" S/n "and so on are simply not working.
If anyone knows how to get into what I would be really grateful for the help.OK, so if you default a field to the value of another object, you must use the JoinFieldValue function. I think you understand that, based on your original post, but I want to be sure you do.
Then this won't work by default if the folder is created from the object that you want to join the because a default works in record creation and the ID must be available so that it works correctly. It will not work if you choose the record of the related object after that registration of the custom object is created. You can set the default after, but that does not meet your requirements.
The syntax of the default are the following: JoinFieldValue (ref_record_type, foreign_key, field_name).
In your case, ref_record_type is '
', foreign_key is [ ] and field_name is ' '. The best way is to determine what is the name of the field to create a new workflow for the account and use the Workflow Rule Condition expression builder to choose your field ("DBA") in the list. The value returned by the expression builder must be placed in the field_name variable in the function JoinFieldValue (minus the parentheses and quotes). Give it a shot and let me know how you do.
Thom -
In the form of table-update a column based on the other
Greetings,
I want to update a column based on the value of another column in a tabular presentation. What should I use? Calculation or validation process?
-VatsaYes, get rid of the update of "pims_component" - this is the cause of the error table mutation - and simply set
: new.state_ind: = Ls_state;
CITY
-
Compare multiple columns and update a column based on the comparison
Hi all
I have to update the column STATUS of the slot structure of the table.
Status should be 'P' if all the columns count are equal on the other should be "F".
The value of the column can be "NA'. If the value is NA, then avoid this comparison column; compare only other 3 columns.
My output should look like below.
State of cnt1, cnt2 cnt3 ID cnt4
1 4 4 4 4 P
2 4 5 4 4 F
3 4 4 NA 4 P
NA 4 4 3 4
I tried with the statemnt with BOX WHEN conditions and DECODE UPDATE, but could not succeed, can someone please help
To do this, if you use my statement in response #11 box (Re: Re: comparison of multi-column and update a column based on the comparison of)
-
How can I insert data from another table into a table containing a timestamp column
How you insert data from another table in a table if the target table contains a timestamp column. I tried to set the default value of GETDATE() column in the target table, but it does not work.
I use MS SQLSorry, I managed to get around this by inserting null as the value
-
How to hide/show a field based on the data from more than 1 field?
Hello.
I'm trying to hide/show a based on the data of field2 and field3, Field1
in fact using dynamic measurements I can only hide/show Field1 Field2-based, but I need a combination, for example:
If field1 = 'A' and field2 = 'B', then see the field3, other hide field3
y at - it an easy way to do it.
I use Application Express 4.2.4.00.08
Thanks in advance
Dynamic action
On the changes
jQuery selector: #P1_ITEM_1, #P1_ITEM_2
Condition: JavaScript
$v ('P1_ITEM_1') == 'A' & $v ('P1_ITEM_2') == 'B '.
Real Action: show item 3
Action of false: hide item 3
-
update of data from another table
Hi, I would like to help. I Don t know how I can start doing:
I have a table with a column with numbers (primary key) and I need to create another column with the same values,
I want to change a table that has only numeric values (PK) to another
value, so I disable the constraints of linked tables
then I create another column that I called the "d" column and copy the values
from column A to column D
For example.
TABLE XYZ
COLUMN A: COLUMN D: (NEW)
00001 00001
00002-00002
00003-00003
00004 00004
Can I change the values in column A and D of the column will be kept
TABLE XYZ
COLUMN A: COLUMN D:
00001 99901
99902 00002
99903 00003
99904-00004
As the tables that must "point" to the column, I change the values with the new numbering
TABLE ZZZZ
COLUMN B: (the values of the column before the change)
00001
00002
00003
00004
...
I want it like this:
99901
99902
99903
99903
99904
...
In other words, I find the current value in column D of the XYZ table for the new value that is in column a.
I appreciate the help! :)Try this
Here you will find a record in test1 for a record for each line of teste2 in teste2 joined the condition t1.numer_documento2 = t2.numero_documento.This is called as subquery related Co. What you were doing was under queries that and not to join the top request.
UPDATE teste2 t2 SET NUMERO_DOCUMENTO = (SELECT T1.NUMERO_DOCUMENTO FROM teste1 t1 WHERE t1.numer_documento2 = t2.numero_documento and ROWNUM = 1 ) -- "Check/Select your data before you commit "
SS
-
To return a specific number of rows based on the data in a table column
Hello
I have a table named orders that has the column orderid and noofbookstoorder in addition to the other columns.
I want to query the orders table and according to the value of the value of "noofbookstoorder" that return number of lines.
For example
OrderID noofbookstoorder
3 s
2 3
3 2
When I ask the above data saying
Select * from orders where orderid = 2;
because there noofbookstoorders 3 value the query should return 3 rows and when I query
Select * from orders where orderid = 3;
He must return to 2 rows and
Select * from orders where orderid = 1;
should return 1 row.
Is it possible to do this. If Yes, then how can I write my query.
Thanks in advance.with t as ( select 1 Orderid,1 noofbookstoorder from dual union all select 2,3 from dual union all select 3,2 from dual ) select t.* from t, table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.OdciNumberList)) where Orderid =
/ For example:
SQL> with t as ( 2 select 1 Orderid,1 noofbookstoorder from dual union all 3 select 2,3 from dual union all 4 select 3,2 from dual 5 ) 6 select t.* 7 from t, 8 table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.OdciNumberList)) 9 where Orderid = 2 10 / ORDERID NOOFBOOKSTOORDER ---------- ---------------- 2 3 2 3 2 3 SQL> with t as ( 2 select 1 Orderid,1 noofbookstoorder from dual union all 3 select 2,3 from dual union all 4 select 3,2 from dual 5 ) 6 select t.* 7 from t, 8 table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.OdciNumberList)) 9 where Orderid = 3 10 / ORDERID NOOFBOOKSTOORDER ---------- ---------------- 3 2 3 2 SQL> with t as ( 2 select 1 Orderid,1 noofbookstoorder from dual union all 3 select 2,3 from dual union all 4 select 3,2 from dual 5 ) 6 select t.* 7 from t, 8 table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.Odc iNumberList)) 9 where Orderid = 1 10 / ORDERID NOOFBOOKSTOORDER ---------- ---------------- 1 1 SQL> -- And if you want to select multiple orders SQL> with t as ( 2 select 1 Orderid,1 noofbookstoorder from dual union all 3 select 2,3 from dual union all 4 select 3,2 from dual 5 ) 6 select t.* 7 from t, 8 table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.Odc iNumberList)) 9 where Orderid in (2,3) 10 / ORDERID NOOFBOOKSTOORDER ---------- ---------------- 2 3 2 3 2 3 3 2 3 2 SQL>
SY.
Published by: Solomon Yakobson, October 26, 2009 07:36
-
How to create a table with a column that is the value in another table?
Hi all,
It's my first post n I changed my ODI of DATASTAGE platform. Help me friends n I know basic steps in 11 ODI version which I was training in my company. I hope to have your support and can do everything an action ODI related documents.
My question is...
Table T1 > > > > > > > > > >
service id / / / attr.name / / / attr.value
S1 / / / product_code / / / P1
S1 / / / provider / / / pro1
S2 / / / product_code / / / P2
S3 / / / provider / / / pro3
Table T2 > > > > > > > > > > > > > > >
ID / / / product_code / / / provider
S1 / / / p1 / / / pro1
S2 / / / p2 / / / nullvalue
S3 / / / nullvalue / / / pro3
I have a table T1 since I should show the table T2 is released. Can we say everything on how to write a logic and steps to follow.
Thanks in advance.
Published by: 854662 on April 26, 2011 01:59Hello
U go.
1 the interface:
"Put a filter in your 1 on attr.name = array ' PRODUCT_CODE.
In the map target TABLE2
SERVICE_ID = TABLE1. SERVICE_ID
PRODUCT_CODE = TABLE1. ATTR_VALUEUse SQL IKM append control
Interface 2:
"Put a filter in your 1 on attr.name = array ' PROVIDER '.
In the map target TABLE2
SERVICE_ID = TABLE1. SERVICE_ID
PROVIDER = TABLE1. ATTR_VALUEDo SERVICE_ID as KEY (when you click the column target in properties, you can see KEY under properties of the target column) and use the incremental update of the IKM Oracle.
PS: I assume that Oracle as the source and target.
And you can refer to the documentation,
https://Apex.Oracle.com/pls/Apex/f?p=44785:24:4413167952886630:no:24:P24_CONTENT_ID, P24_PREV_PAGE:5185, 29
http://odiexperts.com/
And of course this OTN.
Thank you
Guru -
Save the data in another table
Hello, I would like someone to help me with a problem I have in my program.
What makes the program is, for each iteration, take the data in 'table iter' and recorded in "table of output." But in the second iteration instead of storing the results of the first iteration offer me '1' in the first five lines.How can I solve this problem?
Thank you, Jaime
Hi pescajaime,
Please make the change mentioned in the attachments.
Thank you and best regards,
srikrishnaNF
-
Extracting the data from relational tables in 11.1.2.1
I want to extract the following data sets from relational tables
1 attribute and his partner basic member
2 Smartlist value of an account
Have a code to extract such data? It will be useful in pointing to the correct table names.
Thank youYou will find the table schemas in the [documentation for EPMA | http://www.oracle.com/technetwork/middleware/bi-foundation/epm-data-models-11121-354684.zip]. If this does not work, there are other options to export hierarchies in text files. You can use the lifecycle management or the [EPMA line Generator | http://docs.oracle.com/cd/E17236_01/epm.1112/epma_file_gen_user/launch.html].
Kyle Goodfriend
http://www.in2hyperion.comPlease make sure that you assign your post as answered when an appropriate response is provided (or useful when it takes place) as well as other benefits.
-
update of column based on the values of the same table
I have the T1 table with 4 columns "col1", "col2", "col3", "col4", "col5", "col6" as follows
Col1 Col2 Col3 Col4 Col5 Col6
1111 Ville1 C AA DDD A1
2222 city SD HHH A1 1
3333 City2 B EE OOO
4444 City 1 B JJ SSS A1
5555 City2 C KK VVV
6666 City2 RR QQQ
7777 City2 B BBB XX
I've already updated column value 6 'A1' where the 2 column is 'Ville1 '.
Now, I want to update Col. 6 where col2 is the of ' with the following conditions
If Col 3 = 'B', then Col6 should be = col4
Otherwise, it should be = col5SET col6 = DECODE(col3,'B',col4,col5)
"WHERE col2 = s" -
Getting the value of a column based on the value of another column in a max group
Please let me know if there is a simple way to do it. I came up with a way, but it is terribly inefficient and it must work quickly.
GROUP_ID NO_REGISTRE READ_VALUE QUARTERLY
---------- ----------- ---------- -----------------------------
2 1 0.035 00:00:00.000000000 01/01/2015
2 0.035
3 1 1.11 14:50:32.943000000 14/07/2015
3 2 222 01/01/0001 13:36:47.017436000
3 223.11
So what I need is for all no_registre is NULL, I need the value of QUARTERLY for the QUARTERLY to the MAX (READ_VALUE) for this GROUP_ID (not counting the rows where the no_registre is NULL). So the result would look like this:
GROUP_ID NO_REGISTRE READ_VALUE QUARTERLY
---------- ----------- ---------- -----------------------------
2 1 0.035 00:00:00.000000000 01/01/2015
2 0.035 00:00:00.000000000 01/01/2015
3 1 1.11 14:50:32.943000000 14/07/2015
3 2 222 01/01/0001 13:36:47.017436000
3 223.11 13:36:47.017436000 01/01/01
Someone at - it ideas?
Or maybe:
-production of the sample data:
WITH t (GROUP_ID, no_registre, READ_VALUE, QUARTERLY)
AS LONG AS)
SELECT 2, 1, 0.035, TIMESTAMP ' 2015-1-1 00:00:00 ' FROM DUAL
UNION ALL SELECT 2, NULL, 0.035, THE DOUBLE NULL
UNION ALL SELECT 3, 1, 1.11, TIMESTAMP ' 2015-07-14 14:50:32 ' FROM DUAL
UNION ALL SELECT 3, 2, 222, TIMESTAMP ' 0001-1-1-13:36:47 ' FROM DUAL
UNION 3 SELECT ALL, NULL, 223.11, NULL FROM DUAL
)
--
-actual query:
--
Select group_id
no_registre
read_value
, last_value (quarterly) ignores NULL values over (partition by arrested by no_registre last read_value null, group_id) quarterly
t;
-
How to insert into a GLOBAL TEMPORARY TABLE and get the data from it?
The requrement is
Split the string ENTRY point on the base and store it in a Collection. And the values of the collection will be stored in a global temporary table. Then, I'm updating some other table based on the data from the temporary table.
There is in fact no error message. But there is no data in the temporary table and also no change in the update statement
First of all, I'm creatiing a global temporary table only once outside the procedure.
CREATE GLOBAL TEMPORARY table GLt (data_element number)
create or replace procedure test_proc (p_in_string VARCHAR2) is
i the number: = 0;
number of POS: = 0;
CLOB lv_str: = p_in_string;
p_delim VARCHAR2 (1): = ', ';
TYPE t_array IS TABLE OF VARCHAR2 (20) INDEX directory.
t_array channels;
BEGIN
-cutting of string input and store in the strings (i) collection
POS: = instr (lv_str, p_delim, 1, 1);
WHILE (pos! = 0) LOOP
i: = i + 1;
Strings (i): = substr(lv_str,1,pos-1);
lv_str: = substr (lv_str, pos + 1, length (lv_str));
POS: = instr (lv_str, p_delim, 1, 1);
IF pos = 0 THEN
Strings (i + 1): = lv_str;
END IF;
END LOOP;
run immediately "drop table TWG;
run immediately ' CREATE GLOBAL TEMPORARY table (data_element number) TWG on commit preserve rows ";
FORALL i in strings.first... Strings.Last
INSERT INTO VALUES TWG (strings (i));
commit;
Update first_tbl set PIN is "XXX" where first_col in (select data_element from TWG);.
commit;
END test_proc;
Published by: cedric b on January 25, 2013 12:59Remove the two execute immediate line. They are wrong.
And then use the table in your code that you created at the beginning. The name is GLT.
And delete the first commit. This validation would empty the temporary table of GLT.You get an error? Or it does not work as expected?
Also, show how you call the procedure.
Published by: Sven w. January 25, 2013 14:45
-
Delete the data in partitioned tables
Hello
Oracle 11.2.0.3.0 version, running on Linux Enterprise.
I need to remove all the data from two tables (several 100 million lines each) that are partitioned.
(1) table 1 is a partition table have varied to a DATE column
(2) Table2 is a partition of reference table; partitioning is referenced on a relationship of foreign key to Table1 (column: key Table1.Primary)
As I have no need for data, but want to keep the structure of the table, I would ideally like to delete partitions at the same time that the deletion of the data, so that the 2 tables partitioned and empty.
Additionally, Table1 has some partitioned index I would be rebuilt as an index unpartitioned (given that Table1 will be empty).
I thought I would start by removing all partitions of Table1 (via "ALTER TABLE DROP PARTITION nom_partition Table1"), but when the script came to the last partition, I got this error message:
ORA-14083: cannot delete the only one partition of a partitioned table
ORA-06512: at "SYS." DROP_PARTITIONS', line 46
If someone could advise as to the best approach to what I want to achieve with regard to the two tables? Two tables down and recreate them then without partitions would be the easiest way?
Thanks in advance for any guidance.
If someone could advise as to the best approach to what I want to achieve with regard to the two tables? Two tables down and recreate them then without partitions would be the easiest way?
Yes - delete the tables and re-create them.
As says the exception that you cannot delete the last partition. A table is partitioned either or it is not.
There was no interest at all to use DBMS_REDEFINITION to redefine tables because you do not want the data anyway.
Maybe you are looking for
-
How can I change to another registered bookmark previously?
-
RE: Automatic Installation of KB2491683
That said is an automatic update appeared on my screen to be installed. It's in the middle of the week and no time for auto-update function on my machine. Where did this come from? When I saw the link to describe the file that it took me to (http://t
-
HP psc 1317: HP PSC 1317 keeps asking for alignment.
When I turn the computer/printer print on another page of alignment, I went through the alignment process, I ignored the statement, I changed the cartridges, I reinstalled the drivers but every time that I swich on, it displays another! Help please?
-
How to add a VLAN to a B200 M3
I have a M3 of UCS B200, which is a Proxy of veeam backup server and I need to give it access to an additional VIRTUAL local network. There are several other blades with access to the VLAN and I can see it. UCS Manager is 3.1 (h) Thanks for the clues
-
BlackBerry Smartphones Foursquare App - trying to access my location
Please help, I have not downloaded the app Foursquare on my phone (nor even looked on App World) but suddenly the Foursquare application is to appear on my screen and asking to access my location - there is a tab to allow or deny but when hit 'declin