从一个视图里找出某个字段里不相同的所有记录,如果有相同的,则只选一条,把每条记录的所有字段都显示出来,
select * from view1 where productid in( select productid from view1 group by productid having count(*)=1)
这个方法没有把相同的记录选出一条,应该怎么做
select * from view1 where productid in( select productid from view1 group by productid having count(*)=1)
这个方法没有把相同的记录选出一条,应该怎么做
select distinct * from view1如果不同,至少得有一列相同productid情况下它的列值不同,比如时间dt,名称productname等等.
就是dt不同为例,我们取相同productid下dt最大的:select * from view1 A where not exists(select 1 from view1 where productid=A.productid and dt>A.dt)否则,有这种需求,就是你的视图就设计不合理.