sql-update

Update column based on matching values in other table in mysql

人走茶凉 提交于 2020-01-13 09:25:30
问题 I have two tables calendar and customer table. Calendar table have a "customer" column which has customer table "ID" as value. But unfortunately, this calendar customer field value was wrongly populated with other values. Both tables have these common fields Date, SeatingID and BusID. How to update the calendar table customer field based on these common fields?. Below is the structure of both tables. Customer Table calendar Table 回答1: You can UPDATE the Customer field of the second table

Update Table with a “Select query” with a where clause

旧巷老猫 提交于 2020-01-13 01:40:33
问题 I want to achieve the following: Current State of table (my_table) id totalX totalY totalZ --------- -------------- -------------- -------------- 9 34 334 0 10 6 56 0 11 21 251 0 12 3 93 0 Query result of (my_table2) select id,count(*) as total FROM my_table2 WHERE column_2 = 1 GROUP BY id id total --------- -------------- 9 500 10 600 11 700 12 800 Expected State of table (my_table) id totalX totalY totalZ --------- -------------- -------------- -------------- 9 34 334 500 10 6 56 600 11 21

Is there any other approach for updating a row in Big Query apart from overwriting the table?

蹲街弑〆低调 提交于 2020-01-12 05:44:06
问题 I have a package data with some of its fields as following: packageid-->string status--->string status_type--->string scans--->record(repeated) scanid--->string status--->string scannedby--->string Per day, I have a data of 100 000 packages. Total package data size per day becomes 100 MB(approx) and for 1 month it becomes 3GB. For each package, 3-4 updates can come. So do I have to overwrite the package table, every time a package update (e.g. just a change in status field) comes? Suppose I

SQL: How can I update a value on a column only if that value is null?

自闭症网瘾萝莉.ら 提交于 2020-01-12 03:15:27
问题 I have an SQL question which may be basic to some but is confusing me. Here is an example of column names for a table 'Person': PersonalID, FirstName, LastName, Car, HairColour, FavDrink, FavFood Let's say that I input the row: 121312, Rayna, Pieterson, BMW123d, Brown, NULL, NULL Now I want to update the values for this person, but only if the new value is not null, Update: 121312, Rayna, Pieterson, NULL, Blonde, Fanta, NULL The new row needs to be: 121312, Rayna, Pieterson, BMW123d, Blonde,

MySQL - UPDATE query with SET statement dependent on the outcome of the previous SET statement

限于喜欢 提交于 2020-01-11 12:04:16
问题 Here is a tabular representation of what I would like to achieve with an UPDATE statement. +----+----+---+---+----+----------+---------------+---------------+ | ID | A | B | C | D | Calc A | Calc B | Calc C | +----+----+---+---+----+----------+---------------+---------------+ | 1 | 6 | 5 | 2 | 10 | =[A]-[B] | =[Calc A]/[D] | =[B]/[Calc B] | | 2 | 8 | 5 | 2 | 10 | =[A]-[B] | =[Calc A]/[D] | =[B]/[Calc B] | | 3 | 10 | 5 | 2 | 10 | =[A]-[B] | =[Calc A]/[D] | =[B]/[Calc B] | +----+----+---+---+--

MySQL - UPDATE query with SET statement dependent on the outcome of the previous SET statement

岁酱吖の 提交于 2020-01-11 12:03:41
问题 Here is a tabular representation of what I would like to achieve with an UPDATE statement. +----+----+---+---+----+----------+---------------+---------------+ | ID | A | B | C | D | Calc A | Calc B | Calc C | +----+----+---+---+----+----------+---------------+---------------+ | 1 | 6 | 5 | 2 | 10 | =[A]-[B] | =[Calc A]/[D] | =[B]/[Calc B] | | 2 | 8 | 5 | 2 | 10 | =[A]-[B] | =[Calc A]/[D] | =[B]/[Calc B] | | 3 | 10 | 5 | 2 | 10 | =[A]-[B] | =[Calc A]/[D] | =[B]/[Calc B] | +----+----+---+---+--

MySQL - UPDATE query with SET statement dependent on the outcome of the previous SET statement

佐手、 提交于 2020-01-11 12:03:16
问题 Here is a tabular representation of what I would like to achieve with an UPDATE statement. +----+----+---+---+----+----------+---------------+---------------+ | ID | A | B | C | D | Calc A | Calc B | Calc C | +----+----+---+---+----+----------+---------------+---------------+ | 1 | 6 | 5 | 2 | 10 | =[A]-[B] | =[Calc A]/[D] | =[B]/[Calc B] | | 2 | 8 | 5 | 2 | 10 | =[A]-[B] | =[Calc A]/[D] | =[B]/[Calc B] | | 3 | 10 | 5 | 2 | 10 | =[A]-[B] | =[Calc A]/[D] | =[B]/[Calc B] | +----+----+---+---+--

SQLite Insert OR update without losing record data

人走茶凉 提交于 2020-01-11 11:02:34
问题 i have a table "test" with primary keys on "id & "lang" ╔════╦══════╦══════╦═══════╗ ║ id ║ lang ║ test ║ test2 ║ ╠════╬══════╬══════╬═══════╣ ║ 1 ║ zh ║ lol3 ║ lol4 ║ ║ 1 ║ en ║ lol ║ qsdf ║ ╚════╩══════╩══════╩═══════╝ and i want to do insert or update but since you cannot do IF statement im left out with INSER OR REPLACE INTO when i run my query : INSERT OR REPLACE INTO test (id,lang,test) VALUES (1,'en','zaki') i get this ╔════╦══════╦══════╦════════╗ ║ id ║ lang ║ test ║ test2 ║ ╠════╬══

Update row with select on same table

时间秒杀一切 提交于 2020-01-11 04:39:13
问题 I'm trying to update row with same table query. Context: ID | LANG | TEXT ---------------------------------- 1 | EN | Hello 1 | FR | 1 | ES | 2 | EN | Boat 2 | FR | Bateau 2 | ES | I want to : For each row; if TEXT IS NULL ; update it with TEXT value of row with same ID and LANG = 'EN'. What is the SQL request to do something like that ? 回答1: You don't specify the database. The following is standard SQL: UPDATE t SET TEXT = (SELECT text FROM t t2 WHERE t.id = t2.id AND LANG ='EN' AND TEXT IS

Update record of a cursor where the table name is a parameter

我怕爱的太早我们不能终老 提交于 2020-01-11 02:36:19
问题 I am adjusting some PL/pgSQL code so my refcursor can take the table name as parameter. Therefore I changed the following line: declare pointCurs CURSOR FOR SELECT * from tableName for update; with this one: OPEN pointCurs FOR execute 'SELECT * FROM ' || quote_ident(tableName) for update; I adjusted the loop, and voilà, the loop went through. Now at some point in the loop I needed to update the record (pointed by the cursor) and I got stuck. How should I properly adjust the following line of