Re: [SQL ] 關聯查尋
※ 引述《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
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
討論串 (同標題文章)
Database 近期熱門文章
PTT數位生活區 即時熱門文章