我有这样的表:
release release_id
a 1
b 2
c 3
d 4
a 5
f 6
a 7
b 8
如何更新以使同一版本具有相同的ID? 我知道更新命令。但我不知道该怎么做..
答案 0 :(得分:2)
@RequestMapping(value = "/user/search", method = RequestMethod.POST,produces = "text/plain;charset=UTF-8")
public String listUsersSort(
@RequestParam(value="weight") int weight,
@RequestParam(value="gender") String gender,
@RequestParam(value="place") String place,
@RequestParam(value="age") int age,
Model model, Principal principal)
{
System.out.println("int");
if(weight<40 && gender.equals("") && place.equals("") && age<19)
{
model.addAttribute("users", new Users());
model.addAttribute("noparams", "Задайте параметры поиска");
return "searchingUser";
}
else{
model.addAttribute("users", new Users());
model.addAttribute("listUsersSort", usersService.listUsersSort(weight, gender, place, age, principal.getName()));
model.addAttribute("allUserMess", this.dialogService.allNewMessForUser(principal.getName()));
model.addAttribute("countOfFeedbacks", this.feedbackService.checkUnreadFedbacks().size());
model.addAttribute("countOfNewUsers", this.usersService.countOfNewUsers());
return "searchingUser";
}}
答案 1 :(得分:1)
另一种方法是从包含每个release
及其最小release_id
的派生表进行更新。如果每个版本重复多次,派生表可能比子查询更快,因为每个版本的min release_id只检索一次。
merge into mytable t1
using
(
select release, min(release_id) release_id
from mytable
group by release
) t2 on (t1.release = t2.release)
when matched then update
set t1.release_id = t2.release_id
此查询可以利用(release,release_id)