sql过滤重复显示的内容
selectdistinctms_cf01.BRXM,ms_cf01.fyrqFROMMS_CF01where(MS_CF01.fphmisnotnull)andMS_C...
select distinct ms_cf01.BRXM,
ms_cf01.fyrq
FROM MS_CF01
where (MS_CF01.fphm is not null) and
MS_CF01.zfpb = 0 and
MS_CF01.fybz = 1 and
MS_CF01.yfsb = 1 and
MS_CF01.fyck = 7 and
(MS_CF01.fyrq >= to_date('20140127','yyyymmdd') and MS_CF01.fyrq <= to_date('20140128','yyyymmdd'))
order by MS_CF01.fyrq
;
列brxm想过滤只显示一个,以上语句因为有fyrq,好像无法过滤。怎么修改才能吧按列brxm,有重复的只显示一个呢?排序是按fyrq排序 展开
ms_cf01.fyrq
FROM MS_CF01
where (MS_CF01.fphm is not null) and
MS_CF01.zfpb = 0 and
MS_CF01.fybz = 1 and
MS_CF01.yfsb = 1 and
MS_CF01.fyck = 7 and
(MS_CF01.fyrq >= to_date('20140127','yyyymmdd') and MS_CF01.fyrq <= to_date('20140128','yyyymmdd'))
order by MS_CF01.fyrq
;
列brxm想过滤只显示一个,以上语句因为有fyrq,好像无法过滤。怎么修改才能吧按列brxm,有重复的只显示一个呢?排序是按fyrq排序 展开
2个回答
展开全部
一个BRXM可以有 两个fyrq吗?
如果可以,一个BRXM是否取一个最大的或者最小的fyrq就行。
可以写成这样
就只显示一个BRXM了
select distinct ms_cf01.BRXM,
max(ms_cf01.fyrq)
FROM MS_CF01
where (MS_CF01.fphm is not null) and
MS_CF01.zfpb = 0 and
MS_CF01.fybz = 1 and
MS_CF01.yfsb = 1 and
MS_CF01.fyck = 7 and
(MS_CF01.fyrq >= to_date('20140127','yyyymmdd') and MS_CF01.fyrq <= to_date('20140128','yyyymmdd'))
group by ms_cf01.BRXM
order by MS_CF01.fyrq
如果可以,一个BRXM是否取一个最大的或者最小的fyrq就行。
可以写成这样
就只显示一个BRXM了
select distinct ms_cf01.BRXM,
max(ms_cf01.fyrq)
FROM MS_CF01
where (MS_CF01.fphm is not null) and
MS_CF01.zfpb = 0 and
MS_CF01.fybz = 1 and
MS_CF01.yfsb = 1 and
MS_CF01.fyck = 7 and
(MS_CF01.fyrq >= to_date('20140127','yyyymmdd') and MS_CF01.fyrq <= to_date('20140128','yyyymmdd'))
group by ms_cf01.BRXM
order by MS_CF01.fyrq
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询