我想运行更新查询以在我的案例2012-10-28 03:31:01 to 2012-10-28 08:31:01
中的指定日期之间更新PercentAvailability列值0到100。见下图。
如何运行查询以在指定日期之间更新上述数据?
注意:我有很多具有此问题的ApplicationID,所以我怎么能对所有ApplicationID运行查询,我相信我们需要运行JOIN语法,但如果你给出一些提示,那将会很好。
答案 0 :(得分:5)
使用此查询
update your_table
set PercentAvailability = 100
where PercentAvailability = 0
and [DateTime] between '2012-10-28 03:31:01' and '2012-10-28 08:31:01'
或者如果您只想为特定的ApplicationID
更新相同的内容,请执行
update your_table
set PercentAvailability = 100
where PercentAvailability = 0
and [DateTime] between '2012-10-28 03:31:01' and '2012-10-28 08:31:01'
and ApplicationID = 1235
或多个ApplicationID
执行
update your_table
set PercentAvailability = 100
where PercentAvailability = 0
and [DateTime] between '2012-10-28 03:31:01' and '2012-10-28 08:31:01'
and ApplicationID in (1235, 1236, 1237)
或者对于一个大数字或ApplicationID
你可以做一个子查询
update your_table
set PercentAvailability = 100
where PercentAvailability = 0
and [DateTime] between '2012-10-28 03:31:01' and '2012-10-28 08:31:01'
and ApplicationID in (select ApplicationID from another_table where somecondition)