本文介绍了MySQL根据类型分类到特定日期的最近记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,我不能更具体,但我不知道如何在标题中描述我的问题。我不知道如何搜索类似的问题。



所以这里是交易。我有这个表的记录:





如您所见,我有不同类型的不同月份的数据。我的目标是得到最后输入的数量按类型分组,这应该受到日期的限制。



例如:

那么如何形成MySQL查询?任何帮助将不胜感激。



提前感谢

解决方案

现在我只能想到一个子选择版本:

  SELECT类型,金额
FROM表AS t
WHERE dat =(
SELECT MAX(dat)
FROM table
WHERE type = t.type
AND dat )


I'm sorry I can't be more specific, but I don't know how to describe my problem in the title.. respectively I don't know how to search for similar question.

So here is the deal. I have this table with records:

As you can see, I have data, entered on different months with different type. My goal is to get the last entered amount grouped by type and this should be limited by date.

For example:

So how to form the MySQL query? Any help will be appreciated.

Thanks in advance.

解决方案

Right now I can only think of a subselect version:

SELECT type, amount
FROM table AS t
WHERE dat = (
    SELECT MAX(dat)
    FROM table
    WHERE type=t.type
        AND dat <= '2011-03-01'
)

这篇关于MySQL根据类型分类到特定日期的最近记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 17:54
查看更多