将相似项目分组并存储最长时间 [英] Group similar items and store the maximum date

查看:107
本文介绍了将相似项目分组并存储最长时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一张表格,其中包含一天中不同时段的不同物料质量和整数.在所有不同的时间采样.
基本上,我想将相似的回合的样本分析加在一起,并显示最新的样本日期.

举例说明:

表格:

Date_Time轮次没有Batch_Mass

17/02/2012 15:42:35 16 500
17/02/2012 15:38:35 16400
17/02/2012 15:33:35 15 200


正确的输出为:

Date_Time轮次没有Batch_Mass

17/02/2012 15:42:35 16 900
17/02/2012 15:33:35 15 200

基本上,第16轮的最新时间是2012年2月17日15:42:35,累积质量为900

谢谢大家!

Hi Guys,

I have a table containing different materials masses and round numbers over different periods of the day. Samples are taken at all different times.
Basically I would like to add the sample analysis for similiar rounds together, and display however the latest sample date.

To illustrate:

Table:

Date_Time Round No Batch_Mass

17/02/2012 15:42:35 16 500
17/02/2012 15:38:35 16 400
17/02/2012 15:33:35 15 200


The correct output would be:

Date_Time Round No Batch_Mass

17/02/2012 15:42:35 16 900
17/02/2012 15:33:35 15 200

Basically, the latest time for round number 16 was 17/02/2012 15:42:35 and the cumulative mass was 900

Thanks Guys!!

推荐答案

亲爱的朋友,

在轮次上应用group by子句,它将带来您所需的结果.

http://www.tizag.com/sqlTutorial/sqlgroupby.php [
Dear Friend,

Apply the group by clause on the round number it will bring the result you require.

http://www.tizag.com/sqlTutorial/sqlgroupby.php[^]

Thanks


尊敬的Varun,


谢谢您的回答.

我试过使用this,最初它并不能完全正常工作,但是我只使用了max sample_date,它运行得很好.

Dear Varun,


Thank you for the answer.

I have tried using this , initially it did not exactly work, but i just used the max sample_date and it worked perfectly.

SELECT  ROUND_NUMBER,sum(BATCH) as total, max(sample_date) as latest
FROM test
GROUP BY round_number;



ROUND_NUMBER TOTAL LATEST
---------------------- ---------------------- ------ -------------------

16900 2012-02-17 09:02:43
15200 2012-02-17 08:02:14

谢谢.



ROUND_NUMBER TOTAL LATEST
---------------------- ---------------------- -------------------------

16 900 2012-02-17 09:02:43
15 200 2012-02-17 08:02:14

Thanks..


这篇关于将相似项目分组并存储最长时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆