sql-update

Trigger multiply from two tables

旧时模样 提交于 2021-01-28 19:00:51
问题 i need to create a trigger that multiply two fields from two tables, but i have no idea of how to do it, so let's see if you can help me. Two tables, Products (product_name, price) Orders (product_name (foreign key),units_ordered) I need to add another field on table the Orders that multiply price from Products and units_ordered from Orders, so : total_price = price (from products) X units_ordered (from Orders) Thanks in advance, and sorry for my bad english. Regards 回答1: You don't need

In R connected to a database through ODBC, how do I disconnect after running one query to send another query without cancelling the previous?

若如初见. 提交于 2021-01-28 07:11:22
问题 I am new to R and new to Stack Overflow, so apologies if I don't post this correctly! I have R linked to an Access database using the ODBC and DBI packages. I scoured the internet and couldn't find a way to write an update query, so I've created a loop that manually pretty much does the same thing. The problem is that to do this, I am using the dbSendStatement function. It seems that when you use that function you need a way to then end it before moving onto another query, or else you get

UPDATE with jsonb_set() only affects one object in nested array

≯℡__Kan透↙ 提交于 2021-01-28 04:56:31
问题 Trying to update all elements of a nested array in a jsonb column, but only one element is updated. My query: update table_ set value_ = jsonb_set(value_,cte.json_path,cte.namevalue,false) FROM ( select vals2->'ao'->'sc'->'name' as namevalue, ('{iProps,'||index1-1||',value,rules,'||index2-1||',ao,sc}')::text[] as json_path from table_, jsonb_array_elements(value_->'iProps') with ordinality arr1(vals1,index1), jsonb_array_elements(vals1->'value'->'rules') with ordinality arr2(vals2,index2) )

SQL: join two tables (LEFT OUTER JOIN) then update values

前提是你 提交于 2021-01-27 18:33:55
问题 Im trying to update a value in one column based on a value in another table. I can do this if the columns are all in the same table like this: UPDATE wp_posts SET post_date = REPLACE (post_date, 'X', 'Y') WHERE meta_value = 'Z'; But I need to join two tables first before I can update: SELECT * FROM wp_posts LEFT OUTER JOIN wp_postmeta ON post_id = post_id How can I update based on the two tables I have joined? 回答1: Try this way, if you use SQL Server UPDATE WP SET WP.post_date = REPLACE(WPM

How to update with incrementing value

a 夏天 提交于 2021-01-27 13:06:50
问题 I have a table in PostgreSQL that has an ID column that is supposed to be unique. However, a large number of the rows (around 3 million) currently have an ID of "1". What I know: The total number of rows The current maximum value for the ID column The number of rows with an (incorrect) ID of "1" What I need is a query that will pull all the rows with an ID of "1" and assign them a new ID that increments automatically so that every row in the table will have a unique ID. I'd like it to start

Conditional update with jsonb_set()

南笙酒味 提交于 2021-01-27 13:05:58
问题 I have a table in a Postgres 11.3 database with a jsonb column. Trying to update all objects inside a nested array name "iProps" . If the path {iProps -> value -> rules -> ao -> sc} is an object, then the path should be updated from an object to a string with the value {iProps -> value -> rules -> ao -> sc -> name} If the path {iProps -> value -> rules -> ao -> sc} is not present, then the object should be left unchanged. Test setup with query: Fiddle link Desired result: { "iProps": [ {

Is there a non-commercial alternative to Z.EntityFramework.Extensions? [closed]

╄→гoц情女王★ 提交于 2021-01-21 03:44:50
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Improve this question Entity Framework can be very slow on mass insert/update/delete operations. Even the often suggested tweaks to turn off AutoDetectChanges and/or ValidateOnSaveEnabled does not always help. I have come across the Z.EntityFramework.Extensions on NuGet, but it seems

Is there a non-commercial alternative to Z.EntityFramework.Extensions? [closed]

南楼画角 提交于 2021-01-21 03:44:20
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Improve this question Entity Framework can be very slow on mass insert/update/delete operations. Even the often suggested tweaks to turn off AutoDetectChanges and/or ValidateOnSaveEnabled does not always help. I have come across the Z.EntityFramework.Extensions on NuGet, but it seems

Is there a non-commercial alternative to Z.EntityFramework.Extensions? [closed]

拜拜、爱过 提交于 2021-01-21 03:44:12
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Improve this question Entity Framework can be very slow on mass insert/update/delete operations. Even the often suggested tweaks to turn off AutoDetectChanges and/or ValidateOnSaveEnabled does not always help. I have come across the Z.EntityFramework.Extensions on NuGet, but it seems

Select sum until a set amount and then update fields in mysql database

南笙酒味 提交于 2021-01-07 03:23:36
问题 item_id rate status --------- ----------- ------ 1 12 credit 2 10 credit 3 10 credit 4 20 cash 5 55 credit I have the above table, A user inputs and amount of 25. Now I want to update the status of the rows having credit as status from credit to cash until the sum of rate is 25, so in the above table the top 1 rows having a sum of 22 should get a status of cash. Since the user input is 25, I still have a balance of 3 (25-22), this balance should be deducted from the third row making the third