在一个表里的数据怎么要套用在取另外一个表格的数据

09-0908-3008-2009-16
02-0404-1503-0704-08
◇本站云标签8109人阅读
数据库相关(32)
原帖地址:
for ACCESS 数据库:
update a, b set a.name=b.name1 where a.id=b.id
for SQL Server 数据库:
update a set a.name=b.name1 from a,b where a.id=b.id
SET a.[CreatedOn]=b.[Created]
FROM [tbm_trn_Transaction] a,[tbm_trn_Transaction_Redemption]b
WHERE a.[TransactionID]=b.[TransactionID]
AND b.[Created] IS NOT NULL
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:394457次
积分:4701
积分:4701
排名:第5277名
原创:91篇
转载:167篇
评论:24条
(1)(5)(1)(2)(3)(1)(8)(11)(15)(6)(3)(4)(1)(10)(7)(10)(2)(6)(7)(1)(4)(3)(6)(2)(2)(1)(6)(2)(1)(2)(1)(2)(1)(1)(8)(2)(4)(2)(2)(2)(2)(1)(1)(2)(11)(3)(1)(4)(1)(1)(2)(1)(5)(1)(5)(2)(4)(8)(6)(3)(3)(5)(3)(2)(5)(7)(1)(4)(1)(4)(3)(1)苹果/安卓/wp
积分 124, 距离下一级还需 21 积分
权限: 自定义头衔
道具: 彩虹炫, 涂鸦板, 雷达卡, 热点灯, 金钱卡, 显身卡下一级可获得
道具: 匿名卡
购买后可立即获得
权限: 隐身
道具: 金钱卡, 彩虹炫, 雷达卡, 热点灯, 涂鸦板
各位达人,我刚刚学习SAS,有个很棘手的问题。我有两个表,一个是所有产品的价格表,包括产品ID以及产品价格,另一个的每日销售的产品表, 也是包括产品ID以及价格,我每天会下载当日销售的产品表, 然后把价格升高3%,我希望我可以将升高的价格也更新到所有产品的价格表中。
我试过SQL的left join, merge, 好像都没办法。请问这种情况应该怎么办呢?
第一次发帖希望可以帮我解答一下。。。特悬赏10个论坛币。。多谢啦。
Same idea @YobachiLiu, use subquery. And my previous comment was flawed, 'LEFT JOIN' works fine if used in the SELECT statement.
载入中......
千江有水千江月
本帖最后由 邓贵大 于
10:32 编辑
Same idea @YobachiLiu, use subquery.data table1;
& && &&&input client $6.
0
0
aaaaaa 3333
;
data table2;
& && &&&input client $6.
0
0
bbbbbb 2222
;
& && &&&update table1
& && && && && & set paidclaims = (
& && && && && && && && &select totpaidclaims from table2
& && && && && && && && && && &&&where table1.client=table2.client
& && && && && & )
& && && && && & where client in (
& && && && && && && && &select client from table2
& && && && && & );
复制代码And my previous comment was flawed, 'LEFT JOIN' works fine if used in the SELECT statement.
& && &&&create table table3 as
& && && && && & select a.client, coalesce(b.totpaidclaims, a.paidclaims) as paidclaims
& && && && && & from table1 a left join table2 b
& && && && && && && && &on a.client=b.
复制代码
sql用的这么好,佩服!
总评分:&学术水平 + 1&
热心指数 + 1&
信用等级 + 1&
Be still, my soul: the hour is hastening on
When we shall be forever with the Lord.
When disappointment, grief and fear are gone,
Sorrow forgot, love's purest joys restored.
我没太明白什么意思其实,所以胡乱回答个,呵呵
& & & & & & & &
& & & & & & & &
& & & & & & & & 11 20
& & & & & & & & 12 30
& & & & & & & & 13 40
& & & & & & & & ;
& & & & & & & &
& & & & & & & & id = 12 ;
& & & & & & & & price = 33;
& & & & & & & &
& & & & & & & & create table three as
& & & & & & & & select a.*, b.price as new_price from one as a left join two as b
& & & & & & & & on a.id = b.
& & & & & & & &
乱写的,我也不会的
数据库的工作,级联更新,需要触发器,很麻烦,我好奇为什么不把产品价格单独弄出来一个表呢,用的时候只要关联下就可以了
update 产品表 set 价格=价格*1.03
where id in(select id from 销售的产品表);
如果这是个重复性的或者有规律的计算,你可以创建过程或者数据库job或者时间触发器的形式,让服务器系统自动更新,就不用你每天做了
不明白为什么SQL的left join, merge不可以实现。
&然后把价格升高3%&, 奸商!
'left join' no good because PROC SQL doesn't support the syntax in the UPDATE statement.
merge should be OK
Be still, my soul: the hour is hastening on
When we shall be forever with the Lord.
When disappointment, grief and fear are gone,
Sorrow forgot, love's purest joys restored.
milos_luna 发表于
我没太明白什么意思其实,所以胡乱回答个,呵呵
呵呵。理解力很厉害。这个方法是可以的,不过就是会多加一列NEW-Price出来,有什么办法可以只更新那个所有产品的价格表呢?
千江有水千江月
无限扩大经管职场人脉圈!每天抽选10位免费名额,现在就扫& 论坛VIP& 贵宾会员& 可免费加入
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
如有投资本站或合作意向,请联系(010-);
邮箱:service@pinggu.org
投诉或不良信息处理:(010-)
京ICP证090565号
论坛法律顾问:王进律师

我要回帖

更多关于 套用表格数据 打印 的文章

 

随机推荐