1

このエラーは、次のSQLiteクエリで発生します。

select f.rid, c.title, sum(some_expression) as ratio
from doesntmatter
where c.active = 1 or (ratio = 1.0 and c.active = 0
      and c.deactivated in (1, 2, 3, 4, 5)
group by f.rid

この質問は、次のhaving節で解決します。

select f.rid, c.title, sum(some_expression) as ratio
from doesntmatter
where c.active = 1 or (c.active = 0
      and c.deactivated in (1, 2, 3, 4, 5)
group by f.rid
having ratio = 1.0

しかし、私の場合、これは式のセマンティクスを変更します。where元の節にある表現を実現する方法を知っていますか?

4

1 に答える 1

2

基本的に、where 句でエイリアス化された列を参照することはできません。この質問を見て、それを回避する方法を確認してください。

さらに、ステートメントに存在するすべての非集計列select(この場合はc.idと) によってグループに追加する必要がありc.titleます。

ロジックを理解するのが少し難しいため (グループ化が間違っているため)、そのクエリを書き直すのは困難です。

編集:

考え直した後、 を修正する必要があるかもしれませんgroup by

select c.id, c.title, sum(some_expression) as ratio
from doesntmatter
where c.active = 1 or (c.active = 0 and c.deactivated in (1, 2, 3, 4, 5))
group by c.id, c.title
having ratio = 1.0

または多分:

select f.rid, sum(some_expression) as ratio
from doesntmatter
where c.active = 1 or (c.active = 0 and c.deactivated in (1, 2, 3, 4, 5))
group by f.rid
having ratio = 1.0

私はあなたのテーブルのフィールドもデータも解釈方法も知らないので、前の部分であなたを助けることはできません. ただし、group by に存在しないフィールドを選択することはお勧めできません。いずれにせよ、いつでも元のテーブルに戻って結合し、 に表示されるフィールドだけでなく、探している情報を取得できることを覚えておいてくださいselect

于 2012-02-26T14:47:43.780 に答える