Sql语句-临时表

pictureName    version   status

A                             1              0

A                             2               0

A                              1              1

B                             1               0

B                            1                1

B                             0               1

希望得到picture中相同pictureName的最大version中的status为0的结果

Select distinct pictureName from picture---------得到A B

Select pictureName,max(version) as v from picture where pictureName in (Select distinct pictureName from picture) Group by pictureName--------得到 A   2   与   B       1

然后SELECT picture.picturename,picture.version, picture.status FROM picture,(SELECT pictureName,MAX(version) AS v FROM picture WHERE pictureName IN (SELECT DISTINCT pictureName FROM picture) GROUP BY pictureName) AS picTemp WHERE picture.version=picTemp.v AND picture.picturename=pictTemp.picturename AND status=0

这里并没有考虑效率问题.........

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值