Sedang Disiapkan

MySQL UPDATE SET query

# I have the following table:

CREATE TABLE RES (S int, R int, Q int, P int, RES varchar(100), M int );

# With the following contents:

INSERT INTO RES (S,R,Q,P,RES,M) VALUES

(1,1,1,20,"London",1),

(1,1,1,20,"Paris",0),

(1,1,1,20,"London",NULL),

(1,1,1,32,"Paris",NULL),

(1,1,1,11,"Berlin",NULL),

(1,1,2,20,"Newton",1),

(1,1,2,32,"Newton",1),

(1,1,2,32,"Isaac",0),

(1,1,2,11,"Isaac",NULL),

(1,1,2,11,"Newton",NULL),

(1,1,2,11,"Isaac Newton",NULL);

# I want a short UPDATE SET query to populate the NULL values

# after establishing rules indicated by the M field.

# For example, where S=1 and Q=1 and R=1 then we can establish that

# Where RES=London, M=1 and where RES=Paris, M=0

# I understand it needs to be an UPDATE SET statement with a subquery.

# NULLs should be retained where a rule cannot be established.

# The table is built in such a way that there will never be a conflict

# e.g. for RES=London, M will always equal 0 or NULL where S=1 and Q=1 and R=1

# The query should not reference specific values for any field

# The query needs to update all the NULLs where it can,

# and leave the NULLs as they are where it can't.

# the P field is not relevant, but is included to show there is no primary key.

# Secondly, I have the following table

CREATE TABLE QUA (S int, R int, Q int, ANS varchar(100));

# With the following contents:

INSERT INTO QUA (S,R,Q,ANS) VALUES

(1,1,1,"London"),

(1,1,2,"Isaac Newton");

# This establishes rules for populating the RES table with 1s in the M column.

# Where RES.M is NULL, a second UPDATE SET query should update the RES table.

# It should leave other NULLs as they are.

# Please provide two query lines that can be run successfully on [url removed, login to view]

# Many thanks.

Kemahiran: MySQL, Oracle, SQL

Lihat lebih lanjut: update query mysql, sql r, r sql, p sql, query table, qua, isaac, berlin, mysql populate table, mysql update field, mysql update values, update insert sql, update values mysql, insert mysql table, 2013 query, mysql create table, mysql insert update , oracle update statement, mysql update table, sql query field, mysql statement, sql ans, oracle create table, mysql query example, oracle sql query

Tentang Majikan:
( 6 ulasan ) Tunbridge Wells, United Kingdom

ID Projek: #4098734

Dianugerahkan kepada:

lokeshk9936

Hey solved and tested on sqlfiddle. Please see PM.

$30 USD dalam sehari
(4 Ulasan)
3.1

3 pekerja bebas membida secara purata $30 untuk pekerjaan ini

gopisoft

Hi I have over 10 years of experience working with MySQL and will create the required update statements in a quick time. Thanks Gopisoft Private Limited

$30 USD dalam sehari
(53 Ulasan)
5.5
webprof2

Please Check PMB.

$30 USD dalam sehari
(23 Ulasan)
4.6
truongngocthanh

Hello, i can solve your request in 2hours. Thanks

$30 USD dalam sehari
(12 Ulasan)
4.2