如何在sqlite(android)和查询中创建一个sql视图(CREATE VIEW)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10243249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create a sql view (CREATE VIEW) in sqlite(android) and query?
提问by Diana C
So I have a table and I want to create another table using "CREATE VIEW" from sql. I need to make a copy of the table that I am working with so I can use it 2x. My sql query would have to be like this:
所以我有一个表,我想使用 sql 中的“CREATE VIEW”创建另一个表。我需要制作我正在使用的表格的副本,以便我可以使用它 2 次。我的 sql 查询必须是这样的:
SELECT A.time AS Start, B.time AS Stop
FROM time A, time B
WHERE A.id+1=B.id
AND A.bool=1
AND B.bool=0
my initial table is:
我的初始表是:
String sql="create table "+TABLE+" ( "+C_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "
+C_TIME+" TEXT, "+C_BOOL+" NUMERIC)";
so anyone has any ideea where (in my code) I can create the view and how do I query it in android?
所以任何人都有任何想法(在我的代码中)我可以创建视图以及如何在android中查询它?
I can provide code if needed
如果需要,我可以提供代码
Thank you :)
谢谢 :)
回答by
Based on this, you would create the view with the following statement:
基于此,您将使用以下语句创建视图:
CREATE VIEW view_name AS
SELECT A.time AS Start, B.time AS Stop
FROM time A, time B
WHERE A.id+1=B.id
AND A.bool=1
AND B.bool=0
You can create it right after you create the "base" table.
您可以在创建“基本”表后立即创建它。
You can query it just like you would query any other table.
您可以像查询任何其他表一样查询它。