1

我下面有一个mysql语句

select c11 as genre, t3.strGenre, t2.idGenre t2idGenre, t1.idMVideo
from musicvideo t1
join genrelinkmusicvideo t2
on t2.idMVideo=t1.idMVideo
join genre t3
on t3.idGenre=t2.idGenre
where not (c11=strGenre) and genre='Alternative Rock'

这很好用,给了我想要的结果。

现在,当我想将其放入更新语句时,我被卡住了。

update t2
set idGenre=62
where (select c11, t3.strGenre, t2.idGenre t2idGenre
from musicvideo t1
join genrelinkmusicvideo t2
on t2.idMVideo=t1.idMVideo
join genre t3
on t3.idGenre=t2.idGenre
where not (c11=strGenre) and genre='Alternative Rock')

我知道这是不正确的。任何帮助,将不胜感激。

4

2 回答 2

2

尝试:

update genrelinkmusicvideo t2
    join musicvideo t1
       on t2.idMVideo = t1.idMVideo
    join genre t3
       on t3.idGenre = t2.idGenre
set t2.idGenre = 62
where c11 <> strGenre and genre = 'Alternative Rock'

仅供参考,我建议使用 table_alias.column (例如t3.genre = 'Alternative Rock'),因为它使事情变得更加清晰,特别是对于那些还不知道架构的人。

于 2013-10-26T22:35:46.380 回答
0

你可以试试:

update genrelinkmusicvideo 
set idGenre=62
where idGenre IN (select  t2.idGenre 
from musicvideo t1
join genrelinkmusicvideo t2
on t2.idMVideo=t1.idMVideo
join genre t3
on t3.idGenre=t2.idGenre
where not (c11=strGenre) and genre='Alternative Rock')
于 2013-10-26T22:36:14.817 回答