gpt4 book ai didi

mysql - 使用 MySQL 选择最后 5 个条目的 SUM 的最大值?

转载 作者:行者123 更新时间:2023-11-29 05:42:08 25 4
gpt4 key购买 nike

嘿,我不是 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)

我想做的是选择最大(数字)但最后 5 个条目的总和。我试过乱搞,但就是搞不定。

最佳答案

最后五次印象。这个应该做的数字虽然不知道你想总结什么

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'
ORDER BY impressions.number
LIMIT 5

如果你想对 blocks.price 求和,你可以这样做

 SELECT SUM(lastblocks.price) 
FROM (
SELECT
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'
ORDER BY impressions.number
LIMIT 5 ) lastblocks

关于mysql - 使用 MySQL 选择最后 5 个条目的 SUM 的最大值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5905357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com