27,579
社区成员
发帖
与我相关
我的任务
分享
SELECT co.PartnerCode as 零售店编码,ol.CouponCode as 券号,
(case ol.Status when 'Unused' then '未使用' when 'K1Confirmed' then 'K1已确认' when 'BeenUsed' then '已使用' end) as 券状态,
CONVERT(varchar(100), ol.RecordCreatedDate, 20) as 兑换时间
FROM GitiCustomer.CouponOrder CO
join GitiCustomer.CouponOrderLine ol on CO.CouponOrderId=ol.CouponOrderId
SELECT
co.PartnerCode as 零售店编码,
ol.CouponCode as 券号,
(case ol.Status
when 'Unused' then '未使用'
when 'K1Confirmed' then 'K1已确认'
when 'BeenUsed' then '已使用' end) as 券状态,
CONVERT(varchar(100), ol.RecordCreatedDate, 20) as 兑换时间
into #temp
FROM GitiCustomer.CouponOrder CO
join GitiCustomer.CouponOrderLine ol
on CO.CouponOrderId=ol.CouponOrderId
select *,row_number() over(partition by 零售店编码 order by 兑换时间) as RN into #t1 from #temp
update a set 零售店编码='' from #temp as a,#t1 as b where b.RN>1 and a.券号=b.券号
select * from #temp
SELECT co.PartnerCode as 零售店编码,max(ol.CouponCode) as 券号,
(case ol.Status when 'Unused' then '未使用' when 'K1Confirmed' then 'K1已确认' when 'BeenUsed' then '已使用' end) as 券状态,
CONVERT(varchar(100), ol.RecordCreatedDate, 20) as 兑换时间
FROM GitiCustomer.CouponOrder CO
join GitiCustomer.CouponOrderLine ol on CO.CouponOrderId=ol.CouponOrderId
group by co.PartnerCode,(case ol.Status when 'Unused' then '未使用' when 'K1Confirmed' then 'K1已确认' when 'BeenUsed' then '已使用' end),CONVERT(varchar(100), ol.RecordCreatedDate, 20)
加个max应该可以吧~