1

I can't run this query in sqlite:

Cursor c = mDb.rawQuery(
                "SELECT count(sim1.movie_id) FROM stars_in_movies sim1 WHERE "
                        + "EXISTS ( SELECT 1 FROM stars_in_movies sim2 WHERE "
                        + "sim1.movie_id = sim2.movie_id HAVING COUNT(*) = 4) "
                        , null);

This query gets all the movies in the stars_in_movies table that have four actors in them.

I get this run-time error: SQLiteException : A group by clause is required before having

This query runs in my Mysqln terminal, but it looks like sqlite doesn't like it. How can I change the above query to get the same results in SQLite?

4

1 回答 1

0

因此,您要计算movie_id表中有四个条目的 s 的数量。SQL 查询应该是:

SELECT COUNT(*) 
FROM 
(
   SELECT 1
   FROM stars_in_movies
   GROUP BY movie_id
   HAVING COUNT(*) = 4
) s_i_m
于 2012-06-07T02:47:52.957 回答