使用 MySQL 选择最后 5 个条目的总和的最大值?
嘿,我不是 MySQL 的最大专家,但这是我迄今为止获得 MAX 输入的内容
SELECT DISTINCT
websites.id,
websites.title,
websites.url,
websites.screenshot,
impressions.number,
blocks.price
FROM websites
LEFT JOIN blocks ON websites.id = blocks.website
LEFT JOIN impressions ON blocks.id = impressions.block
WHERE status = 1
AND blocks.active = '1'
AND impressions.number = (SELECT MAX(number)
FROM impressions)
我想要做的是 SELECT max(number) 但最后 5 个条目的总和。我尝试过乱搞,但就是无法得到它。
Hey, I'm not the biggest expert with MySQL but here is what I have so far to get the MAX entery
SELECT DISTINCT
websites.id,
websites.title,
websites.url,
websites.screenshot,
impressions.number,
blocks.price
FROM websites
LEFT JOIN blocks ON websites.id = blocks.website
LEFT JOIN impressions ON blocks.id = impressions.block
WHERE status = 1
AND blocks.active = '1'
AND impressions.number = (SELECT MAX(number)
FROM impressions)
What I want to do is SELECT the max(number) but of the sum of the last 5 entries. I've tried messing around but just can't get it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最后五个印象。数字这应该做它不知道你想要总结什么,但
如果你想总结块。价格你可以这样做
The last five impressions.number this should do it don't know what you want to sum on though
If you wanted to sum of blocks.price you could just do
要获取最后 5 条记录,这取决于您排序所依据的列。假设这是一个日期列,那么一个例子是:
To get the last five records, it depends on the column by which you are sorting. Let's assume this is a date column, so then an example would be: