sql - 如何在更新查询时更新有限数量的记录?
问题描述
我们有更新查询,它会更新所有具有相同城市名称和国家/地区的学生记录,但我们只想更新 500 名具有相同城市名称和国家/地区的学生。
这是到目前为止的查询:
update student st
set st.Fee_Call_Opt_uid = (select t.opt_uid
from (select distinct eco.opt_uid
, eco.employee_id
, ct.city_name
, con.country_name
from employee_calling_operator eco
join territory tr
on tr.territory_id = eco.territory_id
join city ct
on ct.territory_id = tr.territory_id
JOIN country con
on con.country_id = ct.country_id) t
where st.city = t.city_name
and st.country = t.country_name
AND st.is_active_flg = 'Y'
and t.opt_uid = :P242_OPT_UID);
请帮帮我。我们正在使用 oracle 11g
解决方案
您可以使用rownum。这是一个简单的例子:
update test
set col1 = 2
where rownum <=2
and col1 is null
这是一个演示:
所以只需添加:
where rownum <= 500
推荐阅读
- node.js - 获取项目的 id 推送到 Mongoose 中的数组
- amazon-web-services - 比较两个 S3 存储桶
- angular - 在角度材料 DatePicker 中突出显示特定月份的特定星期
- c# - C#。定义不同泛型类型的元素列表,但都具有相同的基本类型
- apache-spark-sql - 向 Delta Lake 中的现有表添加新列(Gen2 blob 存储)
- arrays - 如何在 ruby 中使用 rindex 查找索引
- java - 如何使文本框两个字段中数据的条件满足?
- python - 直接从命令行将文件导入python程序
- python - 将默认值传递给 **kwargs
- android-studio - 我如何解决这个在 android studio 中构建失败的问题?