日期:2014-05-17  浏览次数:20663 次

关于mySql中in语句的替换问题
请问下面这语句该怎么优化

SELECT a.id,a.mobile,a.password,a.telecom,a.cityId,a.provinceId,a.gprsSwitch,
a.gprsPackage,a.monternetSwitch,a.imsiNo,a.puk,a.receipt,a.channelStatus
,a.buyTime , a.remarks ,a.price,b.holder,b.balance,b.status
,b.createTime FROM SIM_MANAGER a , SIM_LOG b WHERE a.id=b.simId
AND b.createTime IN (SELECT MAX(createTime) FROM SIM_LOG GROUP
BY simId)

------解决方案--------------------
SQL code

SELECT a.id,a.mobile,a.password,a.telecom,a.cityId,a.provinceId,a.gprsSwitch,
a.gprsPackage,a.monternetSwitch,a.imsiNo,a.puk,a.receipt,a.channelStatus
,a.buyTime , a.remarks ,a.price,b.holder,b.balance,b.status
,b.createTime 
FROM SIM_MANAGER a , SIM_LOG b ,(SELECT MAX(createTime) createTime FROM SIM_LOG GROUP BY simId) c
WHERE a.id=b.simId
AND b.createTime = c.createTime