sqflite:如何在同一rawquery中使用两个列进行选择

发布于 2025-01-22 01:17:42 字数 398 浏览 0 评论 0原文

我想从与操作员或操作员的2列中接收信息,但我无法视觉效果。

我的列标题和我的列cancoria。我想制作一个影响这两个列的选择,类似的内容:selec *从title或cancoria中...

这就是我所拥有的:

final List<Map<String, dynamic>> queryResult = await db
    .rawQuery('SELECT * FROM todos WHERE title like ?', ['%'+queryCourse+'%']); //here i want to complete the select with both columns

I want to receive info from 2 columns with OR operator, but i can not visualice.

I have my column title and my column categoria. I want to make a select that affects both columns, something like this: selec * from title OR categoria where ...

this is what i have:

final List<Map<String, dynamic>> queryResult = await db
    .rawQuery('SELECT * FROM todos WHERE title like ?', ['%'+queryCourse+'%']); //here i want to complete the select with both columns

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

腹黑女流氓 2025-01-29 01:17:42

使用对2列操作员:

final List<Map<String, dynamic>> queryResult = await db
    .rawQuery('SELECT * FROM todos WHERE title LIKE ? OR categoria LIKE ?', 
              ['%'+queryCourse+'%', '%'+queryCourse+'%']);

或:

final List<Map<String, dynamic>> queryResult = await db
    .rawQuery("SELECT * FROM todos WHERE title LIKE '%' || ? || '%' OR categoria LIKE '%' || ? || '%'", 
              [queryCourse, queryCourse]);

我假设对于这两个列,您都将使用相同的参数queryCourse
如果没有,请使用所拥有的参数更改参数。

Use the OR operator for the 2 columns:

final List<Map<String, dynamic>> queryResult = await db
    .rawQuery('SELECT * FROM todos WHERE title LIKE ? OR categoria LIKE ?', 
              ['%'+queryCourse+'%', '%'+queryCourse+'%']);

or:

final List<Map<String, dynamic>> queryResult = await db
    .rawQuery("SELECT * FROM todos WHERE title LIKE '%' || ? || '%' OR categoria LIKE '%' || ? || '%'", 
              [queryCourse, queryCourse]);

I assumed that for both columns you will use the same parameter queryCourse.
If not, then change the parameters with the ones you have.

短暂陪伴 2025-01-29 01:17:42

您想要工会所有操作员。

Select lastName from Employees
UNION ALL
Select lastName from Patients

参见

https://www.sqlitetoriorarorial.net/sqlite-net/sqlite-union/

他们的示例是:

SELECT FirstName, LastName, 'Employee' AS Type
FROM employees
UNION
SELECT FirstName, LastName, 'Customer'
FROM customers;

注意,列必须“匹配”。在这里,我使用“姓氏”。

与列不同,您不能“联合”。在SQLiteTutorial的示例中,第三列是“字符串” ...它可以具有不同的值,但是在Select语句中必须是相同的“数据类型”和序列位置。

请务必阅读有关工会和“联盟”之间不同的文档。

对于“ where”条件,您必须在联合的每个“部分”上指定所有

https://www.techonthenet.com/sqlite/union_all.php

SELECT department_id, department_name
FROM departments
WHERE department_id >= 10
UNION ALL
SELECT employee_id, last_name
FROM employees
WHERE last_name = 'Anderson'

;

You want the UNION ALL operator.

Select lastName from Employees
UNION ALL
Select lastName from Patients

see

https://www.sqlitetutorial.net/sqlite-union/

Their example is:

SELECT FirstName, LastName, 'Employee' AS Type
FROM employees
UNION
SELECT FirstName, LastName, 'Customer'
FROM customers;

Note, the columns must "match". Here I use "lastName".

You cannot "union all" unlike columns. in the example from the sqlitetutorial, the third column is a "string"... it can have different value(s), BUT it must be the same "data-type" and ordinal position in the SELECT statement.

Be sure to read the documentation on the different between UNION and 'UNION ALL'.

For the "where" condition, you'll have to specify on each "part" of the UNION ALL

https://www.techonthenet.com/sqlite/union_all.php

SELECT department_id, department_name
FROM departments
WHERE department_id >= 10
UNION ALL
SELECT employee_id, last_name
FROM employees
WHERE last_name = 'Anderson'

;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文