如何使用Min()函数?
比如有如下数据:
ItemID ToolModulePmTypeSetDate T TFlag
201100201014DWPRS07@AllModuleW_P2011-11-287AY
201100201015DWPRS07@AllModuleW_P2011-12-5 7AY
201100201016DWPRS07@AllModuleW_P2011-12-127AY
201100201017DWPRS07@AllModuleW_P2011-12-197AY
201100201018DWPRS07@AllModuleW_P2011-12-267AY
201200201001DWPRS07@AllModuleM_P2012-1-2 7AY
201100212001DWPRS07@AllModuleM_P2011-8-29 30AY
201100212002DWPRS07@AllModuleM_P2011-9-28 30AY
201100212003DWPRS07@AllModuleQ_P2011-10-2830AY
201100212004DWPRS07@AllModuleQ_P2011-11-2730AY
通过 搜索语句搜索到:
ItemID ToolModulePmTypeSetDate T TFlag
201100201014DWPRS07@AllModuleW_P2011-11-287AY
201200201001DWPRS07@AllModuleM_P2012-1-2 7AY
201100212003DWPRS07@AllModuleQ_P2011-10-2830AY
如何写这个语句呢...
(PmType为不同的,SetDate取 最小日期的数据,)
[解决办法]
select * from tb a where not exists(select 1 from tb where PmType=a.PmType and SetDate<a.SetDate)
[解决办法]
select ItemID,ToolModule,PmType,T,TFlag,min(SetDate) as SetDatefrom tablenamegroup by ItemID,ToolModule,PmType,T,TFlag
[解决办法]
select a.* from tb as a , (select min(SetDate) as MinSetDate,PmType from tb group by PmType) as b where a.PmType=b.PmType and a.SetDate=b.MinSetDate