马兆娟 2021-08-12 14:44 采纳率: 22.2%
浏览 13
已结题

sqlserver 两个表查询,采用子查询,查询过期时间的信息,效率很慢

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 8月20日
    • 创建了问题 8月12日