非常具有挑战的update语句,你能想出来么?我蛋疼了……
时间:2011-12-08
来源:互联网
不知如何说起,我把两个表摆出来吧:
Emp_Tracking表,列几条数据:
AccountNum, SubAccount, AccountType, LastDateWithoutAmount, LastDateWithAmount
————— ————— ————— ——————————— ——————————
100 0 M NULL NULL
100 1 M NULL NULL
100 2 M NULL NULL
100 3 M NULL NULL
100 4 M NULL NULL
100 5 M NULL NULL
101 0 M NULL NULL
101 1 M NULL NULL
101 2 M NULL NULL
101 3 M NULL NULL
Billing_SalesInvoice_Master表,列一些数据:
AccountNum,SubAccount,AccountType, PurchaseDate, InvoiceAmount
---------- --------- ---------- ------------- -------------
1 100 0 M 2011-12-01 00:00:00.000 200.00
2 100 1 M 2011-12-01 00:00:00.000 400.00
3 100 1 M 2011-12-05 00:00:00.000 600.00
4 100 2 M 2011-10-07 00:00:00.000 100.00
5 101 0 M 2011-12-03 00:00:00.000 0.00
6 101 1 M 2011-12-10 00:00:00.000 0.00
7 101 1 M 2011-12-01 00:00:00.000 200.00
8 101 2 M 2011-12-03 00:00:00.000 0.00
9 101 2 M 2011-12-10 00:00:00.000 0.00
10 101 0 M 2011-12-15 00:00:00.000 0.00
11 100 2 M 2011-10-09 00:00:00.000 100.00
我要修改Emp_Tracking表中 LastDateWithoutAmount, LastDateWithAmount这两个字段的值,当在
Billing_SalesInvoice_Master表中具有相同的AccountNum,SubAccount,AccountType并且InvoiceNum=0
时,我要把Billing_SalesInvoice_Master表中的最大的PurchaseDate的值给Emp_Tracking表的LastDateWithoutAmount字段,
如:101 - 0 - M这条记录,应该更新LastDateWithoutAmount=2011-12-15 00:00:00.000
当Invoice > 0时,则更新 LastDateWithAmount字段的值,
如:101 - 1 - M这条记录,应该更新LastDateWithAmount=2011-12-10 00:00:00.000
不知道大家看明白了否?这个批量更新的sql语句,纠结我一天了,蛋疼,提示:不能用游标,因为数据很多,会卡死……
Emp_Tracking表,列几条数据:
AccountNum, SubAccount, AccountType, LastDateWithoutAmount, LastDateWithAmount
————— ————— ————— ——————————— ——————————
100 0 M NULL NULL
100 1 M NULL NULL
100 2 M NULL NULL
100 3 M NULL NULL
100 4 M NULL NULL
100 5 M NULL NULL
101 0 M NULL NULL
101 1 M NULL NULL
101 2 M NULL NULL
101 3 M NULL NULL
Billing_SalesInvoice_Master表,列一些数据:
AccountNum,SubAccount,AccountType, PurchaseDate, InvoiceAmount
---------- --------- ---------- ------------- -------------
1 100 0 M 2011-12-01 00:00:00.000 200.00
2 100 1 M 2011-12-01 00:00:00.000 400.00
3 100 1 M 2011-12-05 00:00:00.000 600.00
4 100 2 M 2011-10-07 00:00:00.000 100.00
5 101 0 M 2011-12-03 00:00:00.000 0.00
6 101 1 M 2011-12-10 00:00:00.000 0.00
7 101 1 M 2011-12-01 00:00:00.000 200.00
8 101 2 M 2011-12-03 00:00:00.000 0.00
9 101 2 M 2011-12-10 00:00:00.000 0.00
10 101 0 M 2011-12-15 00:00:00.000 0.00
11 100 2 M 2011-10-09 00:00:00.000 100.00
我要修改Emp_Tracking表中 LastDateWithoutAmount, LastDateWithAmount这两个字段的值,当在
Billing_SalesInvoice_Master表中具有相同的AccountNum,SubAccount,AccountType并且InvoiceNum=0
时,我要把Billing_SalesInvoice_Master表中的最大的PurchaseDate的值给Emp_Tracking表的LastDateWithoutAmount字段,
如:101 - 0 - M这条记录,应该更新LastDateWithoutAmount=2011-12-15 00:00:00.000
当Invoice > 0时,则更新 LastDateWithAmount字段的值,
如:101 - 1 - M这条记录,应该更新LastDateWithAmount=2011-12-10 00:00:00.000
不知道大家看明白了否?这个批量更新的sql语句,纠结我一天了,蛋疼,提示:不能用游标,因为数据很多,会卡死……
作者: yangchun1213 发布时间: 2011-12-08
InvoiceNum字段在哪
作者: pengxuan 发布时间: 2011-12-08
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28