@_@ 高分求一查询语句,存储过程更好,帮帮想下办法...

hreohreo 2006-04-18 12:48:41
一月,二月,三月,四月,五月....十二月

要求: 查询月份交集```

比如我下拉菜单选择"1月到2月,就要能查询出1月到2月的交集```

1月到3月,就要能查询出1月,2月,3月的的交集```

2月到3月,就要能查询出2月到3月的交集```

有程序也行,最好是ASP的```

在线等...

...全文
188 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
smallfile 2006-04-18
  • 打赏
  • 举报
回复
select * from table where date between '2006-01' and '2006-03'
itblog 2006-04-18
  • 打赏
  • 举报
回复
再说清楚一点~
dulei115 2006-04-18
  • 打赏
  • 举报
回复
不太懂,有没有数据示例可以看看
hreoghost 2006-04-18
  • 打赏
  • 举报
回复
好的,谢谢你``
iChov 2006-04-18
  • 打赏
  • 举报
回复
ASP没调试,自己试试看吧
ghtyan 2006-04-18
  • 打赏
  • 举报
回复
create table tb1(sPhoneid varchar(15),dtCreate DateTime)
insert into tb1
select '001','2006-1-1' union all
select '001','2006-2-5' union all
select '002','2006-2-5' union all
select '002','2006-1-1' union all
select '003','2006-1-2' union all
select '001','2006-1-25'
go

create procedure GetPhoneID(@FistDt DateTime,@LastDt DateTime)
as
select sPhoneid,sum(nums) c3 from
(select sPhoneid,count(sPhoneid) as nums
from [tb1]
where dtCreate>=@FistDt and dtCreate<@LastDt
group by sPhoneid,year(dtCreate),month(dtCreate)
) aa
group by sPhoneid
having count(*)=datediff(month,@FistDt,@LastDt)
go

--查询2006年1,2月份交集(即:2006-1-1与2006-3-1 之间),调用存储过程如下

GetPhoneID '2006-1-1','2006-3-1'

drop procedure GetPhoneID
drop table tb1
iChov 2006-04-18
  • 打赏
  • 举报
回复
存储过程:
--输入年份,开始月份,结束月份,例GetRecord 2006,1,5表示2006年1月到5月
CREATE PROCEDURE GetRecord(@iYear int=2006,@iMonth1 int=1,@iMonth2 int=12) as
BEGIN
Declare @DateStart varchar(10);
Declare @DateEnd varchar(10);
SEt @DateStart=@iYear+'-'+@iMonth1+'-1';--组合开始日期
SET @DateEnd=@iYear+'-'+(@iMonth2+1)+'-1';--组合结束日期(是所选日期的下个月第一天,自己体会)
--查询,大于等于开始月的第一天,小于结束月次月第一天
Select * From Ent_Members Where JoinTime>=@DateStart and JoinTime<@DateEnd;
End

=============
代码:
<%
if isNumeric(Request.form("year")) and isNumeric(Request.Form("month1")) and isNumeric(Request.Form("month2")) then
'调用存储过程
Set rst=conn.execute("GetRecord "&Request.Form("year")&","&Request.Form("month1")&","&Request.Form("month2"))
.....
rst.close
....
end if

%>
<form id="form1" name="form1" method="post" action="">
<select name="year" id="year">
<option>2003</option>
<option>2004</option>
<option>2005</option>
<option selected="selected">2006</option>
<option>2007</option>
<option>2008</option>
</select>
<select name="month1" id="month1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option>...</option>
</select>
<select name="month2" id="month2">
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option>...</option>
</select>
<input type="submit" name="Submit" value="Submit" />
</form>
hreoghost 2006-04-18
  • 打赏
  • 举报
回复
MARK
hreohreo 2006-04-18
  • 打赏
  • 举报
回复
比如1月到2月,相当二个圆相交

我要的是他们相交的那一块集合

1月到3月,就有三个圆相交

1月到5月,就有五个圆 相交

有没有办法,写成存储过\程

再不清楚我也不知道怎么说了```@_@
hreohreo 2006-04-18
  • 打赏
  • 举报
回复
select sPid,c3 from (select a.sPid,(c1+c2) as c3
from
(select sPhoneid as sPid,count(sPhoneid) as c1 from [tbl]
where month(dtCreate)='01' and year(dtCreate)=2006 group by sPhoneid) a,
(select sPhoneid as sPid,count(sPhoneid) as c2 from [tbl]
where month(dtCreate)='02' and year(dtCreate)=2006 group by sPhoneid) b
where a.sPid=b.sPid) aa order by c3 desc

这是列出1月到2月的交集,要是1月到3月,就有1,2,3月了,那存储过程怎么写

还有年分也怎么办
smallfile 2006-04-18
  • 打赏
  • 举报
回复
这种交集应该有个字段啊
hreohreo 2006-04-18
  • 打赏
  • 举报
回复
最好能写成存储过程
hreohreo 2006-04-18
  • 打赏
  • 举报
回复
不是./我要用下拉选择起始时间和截止时间

下拉选择有先择年分,还有月分

然后列出交集

想做成存储过程,但是传递数据不会,

题目不是那么简单的

200分求救
http://community.csdn.net/Expert/topic/4694/4694909.xml?temp=.5366632

http://community.csdn.net/Expert/topic/4694/4694911.xml?temp=1.823062E-02

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧