这是我的查询
SELECT
'UPDATE TABLE1 SET COL_DATE = '||a.col_date||', COL_ID = '''||a.col_id||'''
WHERE COL_VAR = '''||a.col_var||''';' AS sql_query
FROM
(SELECT t2.COL_VAR AS col_var, t2.COL_DATE AS col_date, t3.COL_ID AS col_id
FROM TABLE2 t2 JOIN TABLE3 t3 ON t2.col_var = t3.col_var) a;
我的目标输出是这样的
UPDATE TABLE1 SET COL_DATE = DATE1,COL_ID =' ID1'在哪里COL_VAR =' VAR1&#39 ;; UPDATE TABLE1 SET COL_DATE = DATE2,COL_ID =' ID2'在哪里COL_VAR =' VAR2';
它适用于oracle而不是mySQL ......这在mySQL中是否可行?
答案 0 :(得分:1)
尝试如下..
SELECT
CONCAT('UPDATE TABLE1 SET COL_DATE = ''',
t2.COL_DATE,
''', COL_ID = ''',
t3.COL_ID,
''' WHERE COL_VAR = ''',
t2.COL_VAR,
'''')
FROM
TABLE2 t2
JOIN
TABLE3 t3 ON t2.col_var = t3.col_va;