(急)一个关于sql语句的问题,高手帮忙。

来源:百度知道 编辑:UC知道 时间:2024/06/23 03:18:08
我想从一个表中以 搜索出 inf 字段不重复的信息。例如:
inf address
abc jilin
abc henan
def beijing
cde jiangsu
asd hebei
cde jiangsu
cde zhejiang

而搜索完毕返回的结果是:
inf address
abc henan
def beijing
asd hebei
cde zhejiang
也就是把inf字段重复的去掉,但要记得返回结果也要有address字段。
最好用一句就实现。
我用过 select distinct(inf),address from table 可是不行啊,不知道为什么????
麻烦高手帮忙解答,一定加分。

select distinct inf,max(address) from table group by inf

你是要inf没有重复的查询记录?那么就是下面的,inf有重复的都去掉了。
select inf address from table group by inf having count(inf)=1
如果按照你给出的搜索完毕返回的结果是:
inf address
abc henan
def beijing
asd hebei
cde zhejiang
你address是按照什么要求取?

select inf address from T1,
(select inf ,max(address) add from T1) a
where T1.inf =a.inf and T1.address =a.add

试一下

不太清楚你取address的规则是什么?
重复的字段中,到底怎么取address?

你的要求中只说了INF要不重复,那么在INF重复的情况下,优先取哪个address呢?也就是取address的规则是什么?有了这个才能帮你写脚本啊.