sql - 多条记录的 SQL 更新
问题描述
StartDate Departmentid DateID
Jan 2010 3 500
Febuary 2011 8 501
March 2012 2 503
April 2013 1 504
更新上面的 departmentID 应该具有 DateID 的值
以上 2 列来自不同的表:
StartDate is from [DatesAvaliable]
DepartmentID is from [Persons]
DateID is from [DatesAvaliable]
用于构建它的查询如下:
select i.startdate,DepartmentID,i.id as DateID
from persons p
inner join substitutetable ppk on ppk.id = p.DepartmentID
inner join DatesAvaliable i on i.id = ppk.DateAvaliableID
where departmentID is not null
这个 Table [substitutetable]种在表之间建立了联系,否则我得到的记录是不可能的
如何编写更新查询来更新上述记录
我可以在哪里用 DateID 替换部门 ID 值?
解决方案
If I'm following this correctly, which is confusing to begin with...
But if your select statement gets you what you need, then just turn your select
statement into an update
statement.
select i.startdate,DepartmentID,i.id as DateID
from persons p
inner join substitutetable ppk on ppk.id = p.DepartmentID
inner join DatesAvaliable i on i.id = ppk.DateAvaliableID
where departmentID is not null
** UPDATE **
Update P
Set DepartmentID = i.id
from persons p
inner join substitutetable ppk on ppk.id = p.DepartmentID
inner join DatesAvaliable i on i.id = ppk.DateAvaliableID
where departmentID is not null
推荐阅读
- c++ - 两个具有相同内容的 unordered_set-s 的迭代顺序是否保证相同
- javascript - 动态添加表单数据并附加文件到超级测试中
- groovy - 在 Groovy 中以预定义模式拆分和解析字符串值
- emacs - 从 `Ch k`-command 获取命名扩展的帮助
- reverse-engineering - 可以合理地混淆构造函数配置吗?
- java - 如何为 gatewayreasoncode 编写测试用例以验证原因代码实际上在测试中被截断
- gitpython - Git Python是否存在分支
- r - 微调 vjust ggplot2
- asp.net-mvc-5 - ASP NET MVC5 提交模态窗口不传递模型元数据
- github - 从 VSCode 访问 GitHub 时如何选择使用的帐户?