SQL: Can WHERE Statement Filter Out Specific Groups For GROUP BY Statement
I'm still new to SQL and playing inside a SQLite3 test database. I tried digging online for this answer but could not find an answer. I cannot get my test query to exclude certai
Solution 1:
> SELECT 0 <> 0;
0
> SELECT '0' <> 0;
1
You have string values in your database. Fix them:
UPDATE MyTable
SET Session_ID = CAST(Session_ID AS INTEGER);
Solution 2:
Your methods works for me (as expected) with a simple dataset.
create table tbl (user_id int, session_id int, duration int);
insert into tbl values (1,0,10);
insert into tbl values (1,1,2);
insert into tbl values (2,1,1);
insert into tbl values (3,2,1);
insert into tbl values (4,2,5);
SELECT USER_ID, SESSION_ID, MAX(duration), count(1)
FROM tbl
WHERE SESSION_ID <> 0
GROUP BY USER_ID, SESSION_ID
Post a Comment for "SQL: Can WHERE Statement Filter Out Specific Groups For GROUP BY Statement"