看板 Database 關於我們 聯絡資訊
資料庫名稱: mssql 2005 資料庫版本: 內容/問題描述: 我有A和B兩個資料表 A和B都有 SHON 欄位 , A則有 數量 "NUMS" 、日期 "TXDAYS" 首先必須要A的SHON存在於B資料表 內的才算是有效資料 我本來是用 底下的SQL 查詢特定日期 的數量總數 SELECT sum(NUMS) AS 總數量, 總計 FROM A WHERE SHON in (select SHON from B ) and (TXDAYS ='2006/07/07') ; 但是做月報表的時候需要查31次 會拖到速度 現在我想改成查詢特定日期區間 , 以日作group的數量總數 所以我用了以下的SQL SELECT sum(NUMS) AS 總數量, 總計 FROM A group by TXDAYS having SHON in (select SHON from B ) and (TXDAYS >='2006/07/07') and TXDAYS <='2006/08/01" ; 這樣下SQL的時候 , SHON這個條件會出錯 --;; 目前還不知道要怎麼改subquery的敘述才能達到目標... 希望有前輩可以指點一下T_T -- String temp="relax"; | Life just like programing while(buringlife) String.forgot(temp); | to be right or wrong while(sleeping) brain.setMemoryOut(); | need not to say stack.push(life.running); | the complier will stack.push(scouting.buck()); | answer your life stack.push(bowling.pratice()); | Bone everything -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.134.27.68 ※ 編輯: TonyQ 來自: 220.134.27.68 (09/25 23:07)