student表中插入以下資料:
XH XM XB CSRQ BJ
001 王小明 男 1990-08-01 1
002 張三鳳 女 1988-04-15 2
003 劉國良 男 1992-02-14 2
004 劉小強 男 1991-01-28 1
005 朱偉偉 女 1993-06-12 1
在score表中插入以下資料:
XH YW SX YY
001 78 96 56
002 89 59 97
003 90 76 88
004 92 100 59
005 34 65 91
我想把“張三鳳”YW成績改為89,使用update嵌套陳述句 Upadate scrore set score.YW=99 where score.XH=(select student.XH from student where student.XM=’張三鳳’) 可以實作。
但是我不想用嵌套陳述句,想用inner join來實作,通過下面的幾次嘗試,都失敗了。
1 . db2 "update score set score.YW=89 from score,student where score.XH=student.XH and student.XM='張三鳳'"
2. db2 "update score set score.YW=89 from score inner join student on score.XH=student.XH and student.XM='張三鳳'"
3. db2 "update score inner join student on score.XH=student.XH set score.YW=89 where student.XM='張三鳳'"
4 . db2 "update score inner join student set score.YW=89 on score.XH=student.XH where student.XM='張三鳳'"
這四種都不成功,到底是問題出現在哪里,該怎么正確使用upadate 內套 join啊
uj5u.com熱心網友回復:
用這個:
update score set score.YW=89 from student where score.XH=student.XH and student.XM='張三鳳'
歡迎來看我的博客:《SQL從入門到出門》。
uj5u.com熱心網友回復:
不對,運行不正確。
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0103N The numeric literal "89 from student where score" is not valid.
SQLSTATE=42604
我會使用update,只不過我是想在update里面嵌套inner join進行update
uj5u.com熱心網友回復:
我是說運行以下命令:
db2 "update score set score.YW=89 from student where score.XH=student.XH and student.XM='張三鳳'"
你比較一下,這就是 update 使用 inner join 的寫法。
uj5u.com熱心網友回復:
運行結果出錯uj5u.com熱心網友回復:
我用開發工具執行上面的 update 陳述句是成功的,db2 直接加 sql 陳述句是不是要先連接資料庫?
db2 => connect to hrdb user db2inst1 using xxxxxx
Database Connection Information
Database server = DB2/LINUXX8664 11.1.2.2
SQL authorization ID = DB2INST1
Local database alias = HRDB
db2 =>
update score set score.YW=89 from student where score.XH=student.XH and student.XM='張三鳳'
db2 => DB20000I The SQL command completed successfully.
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/49957.html
標籤:DB2
上一篇:請教:mysql5.7使用mysqld_exporter監控,報權限問題
下一篇:最優化軟體都有哪些,對于非線性優化哪些優化軟體比較好呢?其中lingo可以優化部分非線性規劃,其他不能優化的有什么?
