sql - 将 SQLite 语句移植到 Firebird

标签 sql firebird

我有这个 select 语句在 SQLite 中完美运行:

SELECT extra, count(extra) AS total FROM (SELECT itemID, item, note, sourceItemID, title, collectionName, tagID, modalityID, extra FROM items INNER JOIN factors ON items.itemID = factors.zotero_itemID WHERE collectionID = :collectionID AND (tagID = 4 OR tagID = 1) GROUP BY item) GROUP BY extra

但是当我尝试在 Firebird 上运行它时,我收到此错误消息:

Dynamic SQL Error.
SQL error code = -104.
Invalid expression in the select list (not contained in either an aggregate function or the GROUP BY clause).

请问有人可以告诉我发生了什么事吗? 最好的问候

最佳答案

SELECT extra, count(extra) AS total 
FROM (SELECT extra 
      FROM items 
      INNER JOIN factors ON items.itemID = factors.zotero_itemID 
      WHERE collectionID = :collectionID 
      AND (tagID = 4 OR tagID = 1) 
      ) t
GROUP BY extra

如果您只需要从内部查询中计数 额外,最好不要选择其他查询并按它们分组,因为您无论如何都不使用聚合函数(在内部查询中)。

关于sql - 将 SQLite 语句移植到 Firebird,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33684097/

相关文章:

sql - SQL 中的层次结构搜索

c# - Firebird 数据读取器

plsql - 在 Firebird 中使用 Qt 存储过程

MySQL:将信息从表复制到具有相反值的另一个表

Firebird 2.5.2 更改 blob 子类型

mysql - 在 SQL 中将负整数转换为 DATE

php - SQL 和 Codeigniter 计算定期付款的复利

java - 如何使用 JPA 调用 firebird 可选择存储过程?

php - 如何从 MySQL 数据库中提取某个项目的类别和标签?

php - sql case 查询时参数编号无效错误