我在MySQL中有一个表,名称如下
1-停用所有未使用的图书
isActive = 1 - Active
isActive = 0 - Inactive
is_inuse = 1 - in use
is_inuse = 0 - not in use
I have the query as such
。 。
update books
set is_active=0
where book_name in (select (book_name)
from books
group by book_name
having count(1) >1
) and
is_inuse != 1;
2 - 除了具有最小书籍ID的书籍之外,重命名所有重复书籍,在书名之前附加book_id。 努力对此案进行查询。
答案 0 :(得分:0)
您应该能够使用以下SQL
获取重复书名的列表select t1.book_id, t1.book_name, concat(t1.book_id, t1.book_name) as new_name
from table1 t1,
(
select book_name, min(book_id) as book_id from table1
group by book_name
) t2
where t1.book_name = t2.book_name
and t1.book_id != t2.book_id