SQL重复统计有关问题
SQL重复统计问题

如何这是一个会员4个商品的竞拍记录(查询每一个竞拍商品的最后一次出价记录),这里如何的竞拍数量如何>1,是拆分成2条记录的
---------------------------------------------------------------------------------------------------------------

现在我写了一个语句把数据统计出来了,但是还要去取时间(JingPaiTime),不知道该怎么做了,求大神指点一下
------解决思路----------------------
with t as (select row_number() over (partition by MemberName order by jingpaitime desc) as xh,* from ceb_P_JingPaiItem)
select * from t where xh=1
下面的*替换成你想要的列就行了,仅能在SQL2005以上版本运行。SQL2000不支持row_number()函数
------解决思路----------------------
GROUP BY 中把ID去掉,之前忘了
如何这是一个会员4个商品的竞拍记录(查询每一个竞拍商品的最后一次出价记录),这里如何的竞拍数量如何>1,是拆分成2条记录的
---------------------------------------------------------------------------------------------------------------
select B.JingPaiCode,B.MemberName,B.ProductCode,B.ProductColor,B.ProductSize,B.JingPaiPrice,sum(B.JingPaiNum) as JingPaiNum ,sum(B.CautionMoney) as CautionMoney, B.[Status]
from (
select * from ceb_P_JingPaiItem as A
where A.JingPaiPrice in(select MAX(JingPaiPrice) from ceb_P_JingPaiItem group by JingPaiCode ) and A.MemberName='admin' ) as B
group by B.JingPaiCode,B.MemberName,B.ProductCode,B.ProductColor,B.ProductSize,B.JingPaiPrice,B.JingPaiNum,B.CautionMoney,B.[Status]
现在我写了一个语句把数据统计出来了,但是还要去取时间(JingPaiTime),不知道该怎么做了,求大神指点一下
------解决思路----------------------
with t as (select row_number() over (partition by MemberName order by jingpaitime desc) as xh,* from ceb_P_JingPaiItem)
select * from t where xh=1
下面的*替换成你想要的列就行了,仅能在SQL2005以上版本运行。SQL2000不支持row_number()函数
------解决思路----------------------
GROUP BY 中把ID去掉,之前忘了
SELECT JingPaiCode,MemberName,ProductCode,ProductColor,ProductSize,JingPaiPrice,SUM(JingPaiNum)JingPaiNum,SUM(CautionMoney)CautionMoney
,MAX(CASE WHEN TRN=1 THEN JingPaiTime END)JingPaiTime,Status
FROM(
SELECT ID,JingPaiCode,MemberName,ProductCode,ProductColor,ProductSize,JingPaiPrice,JingPaiNum,CautionMoney,JingPaiTime,Status
,RANK()OVER(PARTITION BY JingPaiCode ORDER BY CautionMoney DESC)PRN
,ROW_NUMBER()OVER(PARTITION BY JingPaiCode ORDER BY CautionMoney DESC,JingPaiTime DESC)TRN
FROM ceb_P_JingPaiItem
)T
WHERE PRN=1
GROUP BY JingPaiCode,MemberName,ProductCode,ProductColor,ProductSize,JingPaiPrice,Status