gs表, gs关联表
SELECT chiye_gs.id,company,gsid,sstime,setime
FROM chiye_gs INNER JOIN chiye_yw ON chiye_gs.id=chiye_yw.gsid
WHERE (sstime IS not NULL) AND setime< GETDATE() and (select COUNT(distinct gsid) from chiye_yw where chiye_gs.id=chiye_yw.gsid and setime >= GETDATE())=0
不加这句话,还可以,加上这个条件后,非常慢,该如何优化。数据表100万条数据 (select COUNT(distinct gsid) from chiye_yw where chiye_gs.id=chiye_yw.gsid and setime >= GETDATE())=0