首页 \ 问答 \ SQL Server仅基于多个列插入新行(SQL Server insert new rows ONLY based on multiple columns)

SQL Server仅基于多个列插入新行(SQL Server insert new rows ONLY based on multiple columns)

我在SO搜索但是找不到任何符合我目的的东西。 我只需要从一个表插入另一个表中的唯一行。 我有:

表格1

id  name    bookid bookname start_date   end_date   rel_date   rel_id
1   horror  1221   rockys    04/01/2016  04/30/2016 05/01/2016 4545
2   horror  1331   elm       04/01/2016  04/30/2016 05/01/2016 5656

表2

id  name    bookid bookname start_date   end_date   rel_date   rel_id
1   horror  1221   rockys    04/01/2016  04/30/2016 05/01/2016 4545
2   horror  1441   elm       04/01/2016  04/30/2016 05/01/2016 5656

我需要在table2中插入table = id = 2的行,并从table1中删除id = 2的行,因为即使其余列匹配,bookid也是不同的。 我试过以下:

insert into table1
select * from table2
where not exists (select * from table2 where table1.id = table2.id
and table1.name = table2.name and table1.bookid = table2.bookid and
table1.bookname = table2.bookname and table1.start_date =  table2.start_date
and table1.end_date = table2.end_date and table1.rel_date =            table2.rel_date
and table1.rel_id = table2.rel_id)

我可以在一个sql块中以任何方式完成所有这些操作吗?


I searched in SO but couldn't find anything for my purpose. I need to insert unique rows ONLY from one table into another. I have:

table1

id  name    bookid bookname start_date   end_date   rel_date   rel_id
1   horror  1221   rockys    04/01/2016  04/30/2016 05/01/2016 4545
2   horror  1331   elm       04/01/2016  04/30/2016 05/01/2016 5656

table2

id  name    bookid bookname start_date   end_date   rel_date   rel_id
1   horror  1221   rockys    04/01/2016  04/30/2016 05/01/2016 4545
2   horror  1441   elm       04/01/2016  04/30/2016 05/01/2016 5656

I need to insert into table1 the row with id = 2 in table2 AND also delete the row with id = 2 from table1, because bookid is different even though the rest of the columns match. I tried following:

insert into table1
select * from table2
where not exists (select * from table2 where table1.id = table2.id
and table1.name = table2.name and table1.bookid = table2.bookid and
table1.bookname = table2.bookname and table1.start_date =  table2.start_date
and table1.end_date = table2.end_date and table1.rel_date =            table2.rel_date
and table1.rel_id = table2.rel_id)

Any way I can do all of this in one sql block?


原文:https://stackoverflow.com/questions/37146915
更新时间:2022-10-04 12:10

最满意答案

简单的纯CSS解决方案:

使用opacity而不是display并将transition-delay设置为2s

<!DOCTYPE html>
<html>
<head>
<style>
.dropbtn {
    background-color: #4CAF50;
    color: white;
    padding: 16px;
    font-size: 16px;
    border: none;
    cursor: pointer;
}

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    opacity: 0;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.dropdown-content a {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
}

.dropdown-content a:hover {background-color: #f1f1f1}

.dropdown:hover .dropdown-content {
    opacity: 1;
    transition: opacity;
    transition-delay: 2s;
}

.dropdown:hover .dropbtn {
    background-color: #3e8e41;
}
</style>
</head>
<body>



<div class="dropdown">
  <button class="dropbtn">Dropdown</button>
  <div class="dropdown-content">
    <a href="#">Link 1</a>
    <a href="#">Link 2</a>
    <a href="#">Link 3</a>
  </div>
</div>

</body>
</html>


Simple pure CSS solution:

Use opacity instead of display and set transition-delay to 2s.

<!DOCTYPE html>
<html>
<head>
<style>
.dropbtn {
    background-color: #4CAF50;
    color: white;
    padding: 16px;
    font-size: 16px;
    border: none;
    cursor: pointer;
}

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    opacity: 0;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.dropdown-content a {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
}

.dropdown-content a:hover {background-color: #f1f1f1}

.dropdown:hover .dropdown-content {
    opacity: 1;
    transition: opacity;
    transition-delay: 2s;
}

.dropdown:hover .dropbtn {
    background-color: #3e8e41;
}
</style>
</head>
<body>



<div class="dropdown">
  <button class="dropbtn">Dropdown</button>
  <div class="dropdown-content">
    <a href="#">Link 1</a>
    <a href="#">Link 2</a>
    <a href="#">Link 3</a>
  </div>
</div>

</body>
</html>

相关问答

更多
  • 将所有:悬停到一个类(例如“.hover”)。 添加mouseover / mouseout事件以在setTimeout中添加“悬停”类。 setTimeout应该检查用户是否仍然悬停在元素上。 Change all your :hover to a class (e.g. ".hover"). Add mouseover/mouseout events to add the "hover" class in a setTimeout. The setTimeout should check if the ...
  • 简单的纯CSS解决方案: 使用opacity而不是display并将transition-delay设置为2s 。