Re: [SQL ] 關聯查尋

看板Database (資料庫)作者 (骨頭)時間18年前 (2006/09/26 11:22), 編輯推噓3(300)
留言3則, 3人參與, 最新討論串3/3 (看更多)
※ 引述《dragon2 ()》之銘言: : ※ 引述《TonyQ (骨頭)》之銘言: : 用group的時候,除了group by的欄位外其他都必須是集合欄位 : 所以句子要改為如下才不會有語法錯誤: : SELECT sum(NUMS) AS 總數量,總計 FROM A group by TXDAYS,SHON having : SHON in (select SHON from B ) : and (TXDAYS >='2006/07/07') and TXDAYS <='2006/08/01" ; : 但這結果可能不是你要的,那就要這樣: : SELECT sum(View_A.NUMS) AS 總數量, sum(View_A.總計) FROM : (SELECT NUMS,總計 FROM A WHERE SHON in (select SHON from B) : and TXDAYS >='2006/07/07' and TXDAYS <='2006/08/01') AS View_A : group by TXDAYS; : 邏輯上等於於先設一個view把不符的過濾掉再group by,只是也能用一個sql完成ꘊ 非常感謝 o(_ _)o 原來設成view_A就可以解決問題了 不過第二段的語法有error 我猜是view沒有包含到group by所引用的TXDAYS SELECT sum(View_A.NUMS) AS 總數量, sum(View_A.總計) FROM (SELECT TXDAYS,NUMS,總計 FROM A WHERE SHON in (select SHON from B) and TXDAYS >='2006/07/07' and TXDAYS <='2006/08/01') AS View_A group by TXDAYS; 目前測過已能解決問題 , 這問題已經困擾我兩個晚上了...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

09/26 12:07, , 1F
對對 要加TXDAYS
09/26 12:07, 1F

09/26 12:36, , 2F
才兩個晚上阿... [茶]
09/26 12:36, 2F

09/26 12:59, , 3F
一個不過才兩千塊的電子報表 兩個晚上夠多了 == ==
09/26 12:59, 3F
文章代碼(AID): #1569pOCP (Database)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):
3
3
文章代碼(AID): #1569pOCP (Database)