看板 Database 關於我們 聯絡資訊
請問一下 我以sql 語法查詢 count id 的數量 在某個時間點 不包含 在某段時間點出現的 id (not in +子查詢) 如下 select count ( distinct ID) , date FROM table where date BETWEEN '20000101' AND '20031231' and ID not in (select distinct ID from table where func_date BETWEEN '19960101' AND '19991231' ) group by ID 發現資料庫過久沒有反應 但語法方面並沒有錯誤 請問各位大大該怎麼解決 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.71.94.1
supisces:先從三年的範圍縮小成三天, 看看查詢時間多久? 03/22 16:14
hukhuk:拆成二個temp table再比對看看 03/22 17:08
s9234140:縮小成三天 還是沒反應耶 03/22 17:51
braveht:子查詢查出來資料比數大概多少? 03/22 20:19
s9234140:幾百筆 03/23 11:17
sai25:建索引 不要用NOT IN 03/23 12:37
roywu607:用 not exists 看看?? 03/23 14:06
slalala:不要用sub qeury 改用join 03/24 10:19
jej:create index idx_1 on table(date, ID); 04/03 22:34
jej:create index idx_2 on table (func_date); 04/03 22:35