作者TonyQ (骨头)
看板Database
标题[SQL ] 关联查寻
时间Mon Sep 25 23:06:35 2006
资料库名称: 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)