Import SQL statements to excel to remove the same data

Source: Internet
Author: User
Tags configuration settings

-- Call the ggggg Database

Use ggggg
Go

-- Global configuration settings

Exec sp_configure 'show advanced options', 1-- Enable advanced settings
Reconfigure-- Initialization settings
Exec sp_configure 'ad hoc distributed queries ', 1-- Enable Distributed Query
Reconfigure-- Initialization settings
Go

-- Import EXCEL to student table

Insert into student
Select * from
OpenRowSet ('Microsoft. Jet. oledb.4.0 ', 'excel 5.0; HDR = yes; database = F: \ student.xls', sheet1 $)
Go

-- Query the data to be excluded
Select * from student s
Where not exists (
Select student. Sid from student where student. sname = S. sname and student. ssex = S. ssex
And student. sadress = S. sadress and student. Sage = S. Sage and
Student. sclass = S. sclass and student. Sid <> S. Sid
)
-- Query duplicate data
Select * from student s
Where exists (
Select * from student where student. sname = S. sname and student. ssex = S. ssex
And student. sadress = S. sadress and student. Sage = S. Sage and
Student. sclass = S. sclass and student. Sid <> S. Sid
)

-- Here 1 is an arbitrary constant and the execution efficiency is high.

select * from student s
where exists (
select 1 from student where student. sname = S. sname and student. ssex = S. ssex
and student. sadress = S. sadress and student. sage = S. sage and
student. sclass = S. sclass and student. sid <> S. sid
)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.