1

我有一个 sql 查询作为 -

SELECT name_1, dpid_clid, city 
 FROM dts_master_dividend 
 WHERE upper(name_1) like upper('%') 
   AND dpid_clid like upper('IN30290243450560%')
 ORDER BY name_1 asc, dpid_clid asc, dividend_type desc

它将结果显示为 -

ABHINAV  BHARTI IN30290243450560    PUNE
ABHINAV  BHARTI IN30290243450560    DELHI
ABHINAV  BHARTI IN30290243450560    PUNE
ABHINAV  DUBEY  IN30290243450560    PUNE
ABHINAV  BHARTI IN30290243450560    PUNE

但我希望我的结果为 -

ABHINAV  BHARTI IN30290243450560    PUNE
ABHINAV  BHARTI IN30290243450560    DELHI
ABHINAV  DUBEY  IN30290243450560    PUNE

这意味着只有唯一的记录集。
我怎样才能得到它?

4

6 回答 6

2

尝试:

select distinct name_1, dpid_clid, city
  from dts_master_dividend
 where upper(name_1) like upper('%')
   and dpid_clid like upper('IN30290243450560%')
 order by name_1 asc, dpid_clid asc, dividend_type desc
于 2012-05-22T10:05:41.493 回答
2

试试这个

select name_1, dpid_clid, city 
from dts_master_dividend 
where upper(name_1) like upper('%') and dpid_clid like upper('IN30290243450560%')
group by name_1, dpid_clid ,city
于 2012-05-22T10:27:46.117 回答
0

只需添加DISTINCT关键字:

SELECT DISTINCT name_1, dpid_clid, city 
 FROM dts_master_dividend 
 WHERE upper(name_1) like upper('%') 
   AND dpid_clid like upper('IN30290243450560%')
 ORDER BY name_1 asc, dpid_clid asc, dividend_type desc

这会从结果集中删除重复的行。对于 MySQL 文档,请参见此处

于 2012-05-22T10:05:56.503 回答
0

使用DISTINCT

SELECT distinct name_1, dpid_clid, city 
 FROM dts_master_dividend 
 WHERE upper(name_1) like upper('%') 
   AND dpid_clid like upper('IN30290243450560%')
 ORDER BY name_1 asc, dpid_clid asc
于 2012-05-22T10:06:06.660 回答
0

它可能取决于您的数据库服务器,但执行此操作的标准方法是使用

SELECT DISTINCT [columns] FROM [table]. 

所以试着在你的查询中加入一个 DISTINCT

select distinct name_1, dpid_clid, city from dts_master_dividend where upper(name_1) like  upper('%') and dpid_clid like upper('IN30290243450560%') order by name_1 asc, dpid_clid asc, dividend_type desc

有关更多信息,请参阅选择不同的 w3schools 页面

于 2012-05-22T10:08:13.677 回答
0

避免使用upper(name_1) like upper('%')and 而不是upper('IN30290243450560%')只使用'IN30290243450560%'.

所以你的查询应该看起来像 -

SELECT DISTINT name_1, dpid_clid, city
FROM dts_master_dividend
WHERE dpid_clid like 'IN30290243450560%'
ORDER BY name_1 asc, dpid_clid asc, dividend_type desc;
于 2012-05-22T10:09:23.393 回答