gpt4 book ai didi

MYSQL View 不填空点补1000

转载 作者:行者123 更新时间:2023-11-29 13:35:25 24 4
gpt4 key购买 nike

以下查询从过去 2 天内提出的问题中获取热门问题。它查看提要表以了解最新讨论的内容,然后搜索标签表以查找其中哪一个最受欢迎。

我只得到大约 60 个结果,这很好,但我需要 1000 个结果。这意味着我需要用随机问题来填补其余部分。

我的 SQL 查询尝试执行此操作,但不会使用 Feed 表中没有的更多问题来填充 View 的其余部分。

CREATE 
ALGORITHM = UNDEFINED
DEFINER = `root`@`%`
SQL SECURITY DEFINER
VIEW `popular` AS
select
`q`.`name` AS `name`,
`q`.`questionUrl` AS `questionUrl`,
`q`.`miRating` AS `miRating`,
`q`.`imageUrl` AS `imageUrl`,
`q`.`foundOn` AS `foundOn`,
`q`.`myId` AS `myId`
from
(`question` `q`
join `feed` `f` ON ((`q`.`myId` = `f`.`question_id`))

join `tag` `t` ON ((`q`.`myId` = `t`.`question_id`)))

where
(`t`.`name` like '%popular%')
group by `q`.`name`
order by (max(`f`.`timeStamp`) >= (now() - interval 1 day)) desc , (`q`.`myId` is not null) desc
limit 0 , 1000comment

最佳答案

如果您需要随机问题,请删除 where 子句并将逻辑移至 order by:

select 
`q`.`name` AS `name`,
`q`.`questionUrl` AS `questionUrl`,
`q`.`miRating` AS `miRating`,
`q`.`imageUrl` AS `imageUrl`,
`q`.`foundOn` AS `foundOn`,
`q`.`myId` AS `myId`
from
(`question` `q`
join `feed` `f` ON ((`q`.`myId` = `f`.`question_id`))
join `tag` `t` ON ((`q`.`myId` = `t`.`question_id`)))
group by `q`.`name`
order by (max(`f`.`timeStamp`) >= (now() - interval 1 day)) desc ,
max(`t`.`name` like '%popular%') desc,
rand()
limit 0 , 1000;

关于MYSQL View 不填空点补1000,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18816599/

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