欢迎投稿

今日深度:

SQL用子查询结果更新多个字段,sql查询表字段

SQL用子查询结果更新多个字段,sql查询表字段


作者:iamlasong

要求:表格的内容需要变更,变更的内容放在一个临时表中,用SQL语句更新正式表中多个字段。

如果更新一个字段,直接用字段名=子查询就可以了,多个字段更新,将字段在括号中并列写出即可,如下:

update tb_jg t
   set t.jgfl = 'sd',
       (     t.zj_code, t.zj_mc) = (select a.zj_code, a.zj_mc
                                      from song_temp a
                                     where a.zj_code = t.zj_code)
 where exists (select 1 from song_temp a where a.zj_code = t.zj_code)

需求:根据子查询创建表,语句如下:

create table sncn_zd_jg as select * from tb_jg where zdbz='1' order by city_code,xs_code;

如果表已经存在,下面语句则可插入查询结果:
insert into sncn_zd_jg select * from tb_jg where zdbz='1' order by city_code,xs_code;



sql 查询一个字段多个值都有的

通用
select * from t1
where exists(select * from(select name,number,max(money) as money from t1 group by name,number) as tmp
where name=t1.name and number=t1.number
and money=t1.money)

sql server 中同时更新带有子查询多个元组的问题

上面报错:返回值明了子查询结返回多字段只使用字段接受(即使用=:表示单字段)=INOK了
update dd
set dprice IN (select sum(book.price*orderdetail.number) from orderdetail,book,dd
where book.bookno=orderdetail.bookno and dd.ddno=orderdetail.ddno
group by dd.ddno)
from orderdetail,book
where orderdetail.bookno=book.bookno
————————————————————————————————————

www.htsjk.Com true http://www.htsjk.com/shujukunews/1986.html NewsArticle SQL用子查询结果更新多个字段,sql查询表字段 作者:iamlasong 要求:表的内容需要变更,变更的内容放在一个临时表中,用SQL语句更新正式表中多个字段。 如果更新一个字段,直接用字...
相关文章
    暂无相关文章
评论暂时关闭