0

我有一张这样的记录表

*************************** 1. row *************************

   did: 98

 brand_name: Aarther P (100+500)

generic: Paracetamol, Aceclofenac

tradename: Aarther P (100+500)

manfactured: Rekvina Pharmaceuticals

unit: 500mg/100mg

type: Tablet

quantity: 10Tablet

 price: 27.9

*************************** 2. row *************************

did: 99

brand_name: Aarther-P

generic: Aceclofenac, Paracetamol

tradename: Aarther-P

manfactured: Rekvina Pharmaceuticals

unit: 100mg/500mg

type: Tablet

quantity: 10Tablet

price: 27.9

*************************** 3. row ************************

did: 100

brand_name: Aarticef (1000mg)

generic: NULL

tradename: Aarticef (1000mg)

manfactured: Alpic Remedies Ltd

unit: 1000mg/vial

type: Injection

quantity: 1Vial

price: 96

我想消除重复的制造名称,因为我已经执行了以下查询

select brand_name,generic,manfactured from drugs_info group by
manfactured;

但它只显示第 1 和第 3 条记录,但我想要第 2 条记录

*************************** 1. row *************************

did: 98

 brand_name: Aarther P (100+500)

generic: Paracetamol, Aceclofenac

tradename: Aarther P (100+500)

manfactured: Rekvina Pharmaceuticals

unit: 500mg/100mg

type: Tablet

quantity: 10Tablet

 price: 27.9

*************************** 3. row ************************

 did: 100

 brand_name: Aarticef (1000mg)

generic: NULL

tradename: Aarticef (1000mg)

manfactured: Alpic Remedies Ltd

unit: 1000mg/vial

type: Injection

quantity: 1Vial

price: 96

如何为我的要求编写选择查询。

4

2 回答 2

0
SELECT * FROM
(select brand_name,generic,manfactured from drugs_info ORDER BY did DESC) abc
 group by manfactured;
于 2013-08-24T07:13:45.427 回答
0

要删除 mysql 中的重复项,请使用 mysql 的多表删除语法:

delete d2
from mytable d1
join mytable d2 on d2.manfactured = d1.manfactured
    and d2.did > d1.did

的额外连接条件d2.did > d1.did确保行不连接到自身,并且每个重复项仅删除一半,同时保留最低 id 行。

于 2013-08-24T07:17:11.223 回答