SQL duplicate field problem, what should I do if SQL removes duplicate items?

Updated on workplace 2024-04-11
14 answers
  1. Anonymous users2024-02-07

    The above data ** format is too messy, can you sort it out?

    Analyze the demand, this is something similar to material inventory records, right?

    out] field represents inbound and outbound assuming that outbound is outbound if out is 1 and inbound if it is 0.

    The easiest way.

    Take zongjia

    select sum(zongjia) from tab1 where pz ='a'

    Take the inventory on hand.

    select sum(shuliang) as ruku from tab1 where pz ='a' and out = 0

    select sum(shuliang) as chuku from tab1 where pz ='a' and out = 1

    Just use select ruku - chuku.

    You can change your design and design needs.

    The outbound quantity is recorded as a negative number.

    then a statement is done.

    select sum(zongjia),sum(shuliang) from tab1 where pz ='a'

  2. Anonymous users2024-02-06

    One sentence can also be achieved, subtract it, add one"-"Number.

    select sum(zongjia),sum(-shuliang) from table where instr(peinum,'a')<>0

  3. Anonymous users2024-02-05

    SQL statements use the distinct keyword to select data that is not duplicated in a field, for example, from company"Only the uniquely different values in the column are selected using the following SQL:

    select distinct company from order;

    The data in the B and C fields of the subject's question are the same, and you can use select distinct A and B from table name to achieve this.

  4. Anonymous users2024-02-04

    Suppose you have the following table:

    The IDs 002 and 005 are duplicates, and one of them should be removed here to achieve the following effect:

    Look**:- Remove duplicate records.

    select id,code,colornum from(select

    row_number() over(

    partition by code+colornumorder by code+colornum) rn,id,code,colornum

    from twocolumns

    awhere

    order by id

  5. Anonymous users2024-02-03

    SQL statements use the distinct keyword to select data that is not duplicated in a field, for example, from company"Only the uniquely different values in the column are selected using the following SQL:

    select distinct company from order;

    The data in the B and C fields of the subject's question are the same, and you can use select distinct A and B from table name to achieve this.

  6. Anonymous users2024-02-02

    1. Right-click the table where you want to set the primary key, and select [Design] to enter the table design window.

    2. In the table design window, select a row or Ctrl+Mouse to select multiple rows, and right-click and select [Set as Primary Key].

    3. If the primary key has been set, you need to delete the primary key first, alter table table name drop constraint primary key name.

    4. In the Index menu of the table, right-click New Index to enter the index creation page.

    5. Database Unique Index - SQL statement setting.

    6. Judge whether the record exists before inserting, modify it if it exists, and add it if it does not exist.

    7. Before inserting, judge whether the record exists, add it if it does not exist, and discard the record if it exists.

  7. Anonymous users2024-02-01

    The materials we need to prepare are: computer, SQL querier.

    1. First, open the SQL querier and connect to the database table you want to query, such as the test2 table.

    2. Click the "Query" button and enter: select a,b,c from test2 group by a;.

    3. Click the "Run" button, and then all the data will be queried out in the form of field a.

  8. Anonymous users2024-01-31

    What they write is feasible for your set of data.

    But according to what you described, it doesn't seem like a good way to write it.

    select a,max(b) from table name is the data you want to be a distinct, but for field b, I only took the largest one.

  9. Anonymous users2024-01-30

    It's easy to get a unique data alone.

    However, if you want to include data in other columns at the same time as you require, the SQL Select statement cannot be implemented because it is a relational database.

  10. Anonymous users2024-01-29

    Anyone with common knowledge of databases knows that your so-called "not affecting B and C" can be achieved???

    Unless all values in columns b and c are the same... In this case, it is the recommended answer of netizens) is no longer controlled in the array of the program,。。

    Brothers,,, ask questions and also consider feasibility.

  11. Anonymous users2024-01-28

    I will.

    select distinct a,b from table.

    The result of the select distinct a from table is 123

  12. Anonymous users2024-01-27

    The landlord's meaning is very clear.,But I don't know much about the database.,According to your meaning, you want to get a column of non-duplicate data is the following:

    select distinct(a) from table so that you can get all the unique data in column A, but when you also need to get the data of the corresponding other columns, in order to ensure the uniqueness of the duplicate data, the data of your other columns must also be unique, such as the maximum (max), the minimum (min) number (count), etc., so your column can be written as follows:

    select distinct(a),min(b),max(c) from table

    The landlord tried my no, and the netizen recommended the answer was obviously wrong!

  13. Anonymous users2024-01-26

    There are three main methods.

    1) Rowid method.

    Based on the rowid attribute of the oracle band, you can determine whether there are duplicate statements (2) and group by methods.

    The group by statement literally means "grouping according to certain rules".

    3) distinct method.

  14. Anonymous users2024-01-25

    Suppose there is a primary key ID and the name column is a duplicate column, the following sentence can find out all the data that is not duplicated:

    select * from table as a where id=(select min(id) from table where name= .

    Based on the above sentence, all duplicate data can be removed:

    delete from table where id not in(select id from table as a where id=(select min(id) from table where name=.

    Performance characteristics: 1) High-performance design, which can make full use of the advantages of WindowsNT.

    2) Advanced system management, support Windows graphical management tools, support local and remote system management and configuration.

    3) Robust transaction processing function, using various methods to ensure the integrity of the data.

    4) Support symmetric multiprocessor structure, stored procedures, ODBC, and have an independent SQL language. With its built-in data replication capabilities, powerful management tools, tight integration with the Internet, and open system architecture, SQLSserver provides an outstanding database platform for users, developers, and system integrators.

Related questions
9 answers2024-04-11

Add the field status to varchar(10) in the database table

update database table name set status = from database table name inner join temporary table name b on database table name. qh = and database table name. tel = >>>More

5 answers2024-04-11

With a view or an index.

create index >>>More

5 answers2024-04-11

F get domain contrast is a formatting function (should be written by yourself), the first parameter (arg prod spec id) according to the second parameter (120) formatting and return the result to the v bill code, according to the function naming method, the above ** should be the standard format for getting the date.

4 answers2024-04-11

dateadd(dd, datediff(dd,0,getdate())0) means to return the current date. >>>More

4 answers2024-04-11

Generally refers to indexing. You don't have to.