Home > Net >  GROUP BY without a first NULL cell
GROUP BY without a first NULL cell

Time:05-25

These are the first 10 lines of my table :

foo

And this is the result i want to come up with :

bar

How can i make this result ?

And is it possible to write the correct query without displaying a null row in the name field when doing a group by ?

CodePudding user response:

The grouping looks like it should be on session_id_current_user with all fields other than avg max(ed) with an existence check to see if there is a name eg

SELECT t.session_id_current_user,
       max(t.name), max(email)...
       , AVG(t.spent_time) 
FROM table t 
where exists (select 1 from t t1 where t1.session_id_current_user = t.session_id_current_user and t1.name is not null)
group by t.session_id_current_user;

CodePudding user response:

Maybe as simple as this?

SELECT t.name, other_columns, AVG(t.spent_time) FROM table t where t.name is not null and length(trim(t.name))>0
group by t.name;
  • Related