Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 每天从每组中获取最后一条记录_Mysql - Fatal编程技术网

Mysql 每天从每组中获取最后一条记录

Mysql 每天从每组中获取最后一条记录,mysql,Mysql,我做了一个查询来选择所有指标的总和,一切都很好,但我不知道如何选择一个月最后一天的CommunitySize数据/AccountId 现在,查询返回每月第一天的CommunitySize数据/AccountId 我的问题是: SELECT a.Id AS AccountId, a.Name AS AccountName, a.Label AS AccountLabel, a.Status AS AccountStatus, a.Link AS AccountLink, sp.Name AS So

我做了一个查询来选择所有指标的总和,一切都很好,但我不知道如何选择一个月最后一天的CommunitySize数据/AccountId

现在,查询返回每月第一天的CommunitySize数据/AccountId

我的问题是:

SELECT
a.Id AS AccountId,
a.Name AS AccountName,
a.Label AS AccountLabel,
a.Status AS AccountStatus,
a.Link AS AccountLink,
sp.Name AS SocialPlatformName,
sd.Date AS SocialDataDate,
SUM(sd.Comment) AS Comments,
SUM(sd.PostLike) AS PostLikes,
SUM(sd.TotalReach) AS TotalReach,
SUM(sd.Share) AS Shares,
SUM(sd.Click) AS Clicks,
sd.CommunitySize,
c.Id AS CountryId,
c.CountryName AS CountryName
FROM social_data sd, account a, country c, social_platform sp
WHERE sd.AccountId = a.Id AND a.CountryId = c.Id AND sd.AccountId IS NOT NULL AND a.TypeId = sp.Id AND a.Status = 1
GROUP BY MONTH(sd.Date), sd.AccountId

提供sqlfiddle可能非常困难nice@Vanojx1对不起,我工作上有些事要做。等我有空时,我会试着提供一个sqlfiddlehome@Vanojx1SQLFIDLE的字符限制为8000。我无法为我的问题提供合适的sqlfiddle。。。