gpt4 book ai didi

sql - 如何在 SqlLite View 语句上放置 where 条件?

转载 作者:行者123 更新时间:2023-12-03 17:53:47 25 4
gpt4 key购买 nike

是否可以重写以下 View ,以便用户可以使用 WHERE 参数化 View 子句(WHERE overlap > @param,下面注释掉)?有可能吗? where子句应该在 group by 之前生效条款。
我尝试从表中选择 vl并将行(外连接)与语句中的行匹配,该语句在另一个表( vlda )中计数。

CREATE VIEW dr AS
SELECT
vl.unique_object_id AS unique_object_id,
ifnull(vlda.detectioncount, 0) AS detectioncount,
vl.count AS labelcount,
(1.0*ifnull(vlda.detectioncount, 0) / vl.count) AS detectionrate,
vlda.evalround_id
FROM viewlabelcount vl
LEFT OUTER JOIN
(
SELECT
count() as detectioncount,
unique_object_id,
evalround_id
FROM viewlabeldetections_best
-- WHERE overlap > 0.5 -- is it possible to parametrize?
GROUP BY unique_object_id
) AS vlda
ON
vl.unique_object_id = vlda.unique_object_id

最佳答案

SQLite 不允许在存储在模式中的对象(例如 View 或触发器)中使用参数。

如果您使用 SQLite 3.8.3 或更高版本,您可以将该定义移动为 common table expression进入您的查询。

关于sql - 如何在 SqlLite View 语句上放置 where 条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23089335/

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