求一条mysql数据库sql语句

来源:百度知道 编辑:UC知道 时间:2024/09/18 07:48:10
表1:tieba 字段:tt
表2:huishou 字段:group

要让当huishou表中的group为2的时候,将tieba表中的tt内容改为“重要贴”,请问update怎么写?

update tieba set tt=重要贴 where..??
谢谢javainlife,不过我只要在pma执行就好,不用触发。
update tieba set tt='重要贴' where
就是不知道条件怎么写,要条件另外表的字段。

一条语句 :
update tieba set tt=‘重要贴 where huishou.grout = 2;
这样 应该不行;一条语句 不能达到。

估计你的意思要用 到 一个触发器:
当 group 插入或修改一条数据让 group = 2 的时候 激活触发器 来修改 tieba的字段。

create trigger Update_tieba
after insert or update on huishou for each row
as begin
declaer @amount int
select @amount = group from huishou
if(amount==2){
update tieba set tt='重要贴'
}
end

大体是这样的。

如果单独创建一个那两个字段的视图一句更新就好写了。
什么也不弄 ,你看看这样行吗?

update tieba,huishou set tieba.tt='重要贴' where huishou.group = 2;

不知道 mysql 支持这样吗,不行的话,我也没好的办法了。

就这么一个字段怎么写哦?