怎样select 出重复的记录后删除,sql how to 写?

gum 2001-08-14 10:25:40
...全文
74 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tikkypeng 2001-08-16
  • 打赏
  • 举报
回复
Select Distinct 字段 From 表~~就可以了~~
Distinct就是去处相同行~~
lanren 2001-08-16
  • 打赏
  • 举报
回复
建一个临时表,先insert into加dinstict的select 语句先将不重复的记录倒入临时表,清空原表,再倒回来
nne998 2001-08-16
  • 打赏
  • 举报
回复
如果你的目的是整理表(删除重复)的话,可以这样:
while true do
begin
with query1 do
begin
close;
sql.clear;
sql.add('select * from 表名 group by 字段 having count(*)>1');
open;

if recordcount=0 then break;

first;
while not eof do
begin
delete;
next;
end;
end;
end;

ch81 2001-08-14
  • 打赏
  • 举报
回复
dinstict加上去即可。不同的才出现。
tob 2001-08-14
  • 打赏
  • 举报
回复
用distinct就可以了。
xiaoxinxx168 2001-08-14
  • 打赏
  • 举报
回复
为什么要查出后再删除?为什么不用select distinct(ZGBH) from table来去掉重复的记录?
(ZGBH为表中的一个字段。)
Businesses are gathering data today at exponential rates and yet few people know how to access it meaningfully. If you’re a business or IT professional, this short hands-on guide teaches you how to pull and transform data with SQL in significant ways. You will quickly master the fundamentals of SQL and learn how to create your own databases. Author Thomas Nield provides exercises throughout the book to help you practice your newfound SQL skills at home, without having to use a database server environment. Not only will you learn how to use key SQL statements to find and manipulate your data, but you’ll also discover how to efficiently design and manage databases to meet your needs. You’ll also learn how to: Explore relational databases, including lightweight and centralized models Use SQLite and SQLiteStudio to create lightweight databases in minutes Query and transform data in meaningful ways by using SELECT, WHERE, GROUP BY, and ORDER BY Join tables to get a more complete view of your business data Build your own tables and centralized databases by using normalized design principles Manage data by learning how to INSERT, DELETE, and UPDATE records Table of Contents Chapter 1. Why Learn SQL? Chapter 2. Databases Chapter 3. SQLite Chapter 4. SELECT Chapter 5. WHERE Chapter 6. GROUP BY and ORDER BY Chapter 7. CASE Statements Chapter 8. JOIN Chapter 9. Database Design Chapter 10. Managing Data Chapter 11. Going Forward Appendix A. Operators and Functions Appendix B. Supplementary Topics
What this book covers Chapter 1, Microsoft SQL Server Database Design Principles, explains the database design process and the architecture and working of the SQL Server 2014 Storage Engine. This chapter covers the database development life cycle in detail, including the normalization and denormalization process, beneits of choosing appropriate data types, and the functioning of the SQL Server 2014 Storage Engine. Chapter 2, Understanding DDL and DCL Statements in SQL Server, introduces the reader to the SQL Server 2014 Transact-SQL language elements and SQL Server 2014 Management Studio (SSMS 2014). This chapter explains Transact-SQL DDL, DCL, and DML language elements in detail, and how you can use them to create, manage, and secure SQL Server 2014 databases, schemas, and tables. This chapter also shows you how you can use SQL Server Management Studio to create and manage SQL Server 2014 databases, schemas, and tables. Finally, this chapter covers the purpose of SQL Server 2014 system databases and highlights the advantages and disadvantages of database recovery models. Chapter 3, Data Retrieval Using Transact-SQL Statements, demonstrates how to query data from tables, how to write multiple table queries, and how to group, organize, and pivot result set data. This chapter explores the basic form of the SELECT statement and how it can be used to query data from tables. This chapter also highlights the different categories of built-in T-SQL functions and how you can use them in your SELECT statements. This chapter also explains different techniques that you can use to combine data from multiple tables, how to organize the data, and how to generate the summary data by grouping or pivoting it. Finally, this chapter covers the purpose of the CTE and SQL Server 2014 windowing functions and how to use them to quickly solve complex analytical tasks. Chapter 4, Data Modiication with SQL Server Transact-SQL Statements, illustrates how to add, modify, and delete data in tables using Transact-SQL DML statements. This chapter covers how to add data to a table using the INSERT statement, how to delete the data using the DELETE statement, and how to update existing data using the UPDATE statement. This chapter also covers the SELECT…INTO, MERGE, and TRUNCATE TABLE statements, and it highlights the key new enhancements of these statements in SQL Server 2014. Chapter 5, Understanding Advanced Database Programming Objects and Error Handling, covers reusable programming objects that includes views, stored procedures (normal and natively compiled), functions and triggers (based on either DDL or DML), SQL Server 2014 control-of-low statements, and structured error handling blocks. This chapter shows you how you can declare and use variables and how you can use control-of-low statements to control your program execution. Next, it explains the purpose of views, stored procedures, user-deined functions, and triggers, and highlights the guidelines and restrictions to design each of these programmable objects. This chapter also illustrates how to handle errors that occur within Transact-SQL batches and programmable objects using the TRY...CATCH construct. Chapter 6, Performance Basics, explains performance-related features of SQL Server 2014. This chapter irst explains the architecture of the SQL Server Relational Engine. Then, it introduces the architecture of the SQL Server 2014 in-memory technology. Next, it covers all SQL Server 2014 index types and how they can be used to achieve optimal query performance while reducing the overall response time. Then, it explores the architectural differences of B-tree, Bw-tree, and xVelocity columnstore indexes. Finally, it explains core performance topics such as SQL Server query optimization statistics, SQL Server transactions and locks, and tools that come with SQL Server 2014 Database Engine, which you can use to monitor and troubleshoot its Database Engine performance.

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧