本文介绍了MySql中按第一个查询分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将以下(sql in access)转换为mysql.是group by first查询,但是obv mysql不能处理first或last.

I need to convert the following (sql in access) to mysql. It is a group by first query, but obv mysql can't handle first or last.

SELECT First([20121202].Date) AS FirstOfDate, First([20121202].Time) AS FirstOfTime, [20121202].HomeMatchingId, [20121202].AwayMatchingId, [20121202].RunningStatus
FROM 20121202
GROUP BY [20121202].HomeMatchingId, [20121202].AwayMatchingId, [20121202].RunningStatus
HAVING ((([20121202].RunningStatus)=1))

基本上我是在比赛(主队对客队)开始的时间之后(runningstatus = 1)

Basically I am after the time at which the game (hometeam v awayteam) goes in play (runningstatus = 1)

提前致谢

推荐答案

不确定日期是什么,但如何使用常规聚合?

Not sure what the date is for, but what about using the regular aggregates?

SELECT 
    MIN(`Date`) AS `FirstOfDate`, 
    MIN(`Time`) AS `FirstOfTime`, 
    `HomeMatchingId`, 
    `AwayMatchingId`, 
    `RunningStatus`
FROM `20121202`
GROUP BY 
    `HomeMatchingId`, 
    `AwayMatchingId`, 
    `RunningStatus`
HAVING 
    `RunningStatus`=1

这篇关于MySql中按第一个查询分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 14:38