select distinct sessionid
from table_3 a
where not exists (select 1 from table_3 b where a.sessionid =b.sessionid and b.path is not null)
一般用上面这个写法就好了,比较好理解,
当然,下面的这个也可以输出相同的结果,代码更短
select a.sessionid
from table_3
group by a.sessionid
having count(path) =0
有些初学者可能会像下面这样写,不能算错,但某些情况下,查询效率会比较低
select distinct sessionid
from table_3 a
where sessionid not in (select sessionid from table_3 b where b.path is not null)