gpt4 book ai didi

mysql - 如何在 ruby​​ on rails 中编写嵌套查询?

转载 作者:可可西里 更新时间:2023-11-01 07:08:16 26 4
gpt4 key购买 nike

我想使用 where 方法为以下内容编写一个查询

SELECT * FROM videos 
WHERE 'privacy' = 'public' OR
(privacy = 'private' AND
id IN (SELECT vid
FROM vid_ads
WHERE 'aid'=#{current_id}))

我尝试使用以下查询但以语法错误结束

Video.where("privacy = 'public' OR 
(privacy = 'private' AND id = ?)",
VidAd.where(:aid => current_id).select("vid"))

请帮忙

最佳答案

希望这能奏效!

Video.where("category = #{@static_cat} AND
privacy = 'public' OR
(privacy = 'private' AND
id IN (?))",
VidAd.where(:aid => current_id).select("vid"))

关于mysql - 如何在 ruby​​ on rails 中编写嵌套查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17697709/

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