本文介绍了如何计算日期数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
表:
Table :
cmn_minor_code Course_start_date Batch_ID bthidd
PSSR 20 Feb 2014 B13227 PSSR/B1269
STSDSD 20 Feb 2014 B13263 STSDSD/B95
SSO 20 Feb 2014 B13716 SSO/B255
STSDSD_C 20 Feb 2014 B13939 STSDSD C/B58
DECGS 20 Feb 2014 B14218 DECGS/B17
STSDSD 20 Feb 2014 B14340 STSDSD/B96
SSO 20 Feb 2014 B14473 SSO/B256
高于表数据日期明智的计数数据我想要低于结果
Above Table Data Date wise Count data i want below Result
cmn_minor_code count Course_start_date Batch_ID bthidd
PSSR 1 20 Feb 2014 B13227 PSSR/B1269
STSDSD 2 20 Feb 2014 B13263 STSDSD/B95
SSO 2 20 Feb 2014 B13716 SSO/B255
STSDSD_C 1 20 Feb 2014 B13939 STSDSD C/B58
DECGS 1 20 Feb 2014 B14218 DECGS/B17
以上结果明智后表SSO两次出现Bthidd值SSO / B255和SSO / B256这个bthidd哪一个大于值得
我想要结果SSO / B256
谢谢
After Above Result wise Table SSO two times occur Bthidd values SSO/B255 and SSO/B256 this bthidd which one greater than value get
I want result SSO/B256
Thanks
推荐答案
SELECT t1.*, t2.bthidd
FROM (
SELECT cmn_minor_code, Course_start_date, MAX(Batch_ID) AS Batch_ID
FROM @tmp
GROUP BY cmn_minor_code, Course_start_date
) AS t1 INNER JOIN @tmp AS t2 ON t1.Batch_ID = t2.Batch_ID
结果:
Result:
DECGS 2014-02-20 00:00:00.000 B14218 DECGS/B17
PSSR 2014-02-20 00:00:00.000 B13227 PSSR/B1269
SSO 2014-02-20 00:00:00.000 B14473 SSO/B256
STSDSD 2014-02-20 00:00:00.000 B14340 STSDSD/B96
STSDSD_C 2014-02-20 00:00:00.000 B13939 STSDSD C/B58
如您所见,已消除了两行: B13716
和 B13263
。
实现这一目标的其他方法很少。如果你想了解它们,请告诉我。
As you can see, two rows has been eliminated: B13716
and B13263
.
There are few other ways to achieve that. If you want to get to know them, please, let me know.
这篇关于如何计算日期数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!