将SQLite语句移植到Firebird

时间:2015-11-13 00:43:17

标签: 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).

请有人知道发生了什么事吗? 最好的问候

1 个答案:

答案 0 :(得分:3)

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

如果您只需要内部查询count extra,最好不要选择其他人group by,因为您还没有使用聚合函数(在内部查询)。