为 SQLite3 创建动态查询
我在数据库中有 2 个表。
表 2 具有表 1 所需的值
示例
表 1 具有以下字段
名称 食用色素 食物气味 食物烹饪风格
众所周知,某些食物可以通过多种方式烹饪(同时产生相同的结果)。一种方法是为每个变体创建一个新行。
表 2 将包含 FoodCookingStyle 的数据,例如 FoodCookingStyle=1 OR FoodCookingStyle=2 OR FoodCookingStyle=3
所以结果是我想创建一个查询,使用 Table2 的结果来生成一个看起来像这样的 SQL 查询
SELECT * FROM TABLE1 WHERE FoodCookingStyle=1 OR FoodCookingStyle=2 OR FoodCookingStyle=3
(唯一的区别是我想查询 table2 而不是键入表达)。
使用的数据库类型是 SQLite3。
谢谢你
澄清我的意思。 我需要将 table2 的输出作为 table1 的输入
I have 2 tables in a DB.
Table2 has values that would be needed for Table1
Example
Table1 has the following fields
Name
FoodColor
FoodSmell
FoodCookingStyle
As we all know certain foods can be cooked in a variety of ways (while producing the same results). One approach is to create a new row for each variation.
Table2 would have data for FoodCookingStyle like
FoodCookingStyle=1 OR FoodCookingStyle=2 OR FoodCookingStyle=3
So the result is I want to create a Query that uses the results from Table2 to produce a SQL Query that would look like
SELECT * FROM TABLE1 WHERE FoodCookingStyle=1 OR FoodCookingStyle=2 OR FoodCookingStyle=3
(only difference is I want to query table2 instead of typing out the expression).
Type of DB being used is SQLite3.
Thank you
To clarify what I meant.
I need the output for table2 to be the input for table1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题有点令人困惑。您正在寻找子查询吗?子查询语法类似于 SELECT * FROM Table1 WHERE FoodCookingStyle IN
(从 Table2 中选择 FoodCookingStyle,其中 FoodCookingStyle=1 或 FoodCookingStyle=2 或 FoodCookingStyle=3)
The question is a bit confusing. Is it subqueries you're looking for ? Subquery syntax is along the lines of
SELECT * FROM Table1 WHERE FoodCookingStyle IN
( SELECT FoodCookingStyle FROM Table2 WHERE FoodCookingStyle=1 OR FoodCookingStyle=2 OR FoodCookingStyle=3 )