这样可以:
Select count(distinct MyId) from Mytable where MyDate>'2001-6-1' and MyDate<'2001-7-1'
Select count(distinct MyId) from Mytable where MyDate>'2001-6-1' and MyDate<'2001-7-1'
解决方案 »
- 搞编程的,晒晒你的年龄,我是不是挺老的了。
- 紧急问题:使用SetLength()函数,其中申请的空间超过超个1亿个字符。出现内存错误,求紧急解决方法。多谢
- 关于dbedit控件输入问题。好像很简单
- 急求DELPHI 7聊天室源码
- Delphi AdvStringGrid合并单元格垂直居中
- 谁能推荐几篇图像识别的基本教程?
- 大家讨论一下DelPhi安装程序制作问题(解决我等菜鸟问题)欢迎高手发言(鼓掌)
- 100分求像windows搜索那样的控件API函数!!!
- 有没有专门定制工具栏的控件,就像IE的工具栏那样可定制?如果没有这方面的控件,那就请讲讲办法吧!
- chris2019(牛虻——饮马流花河)是个流氓,信誉度为0,大家近来看看,千古罕有的骗子,我劝大家不要上当。
- delphi6 求救:::接收邮件 主题 编码问题 求救!!!!!!!!!!(不是mime问题哦)
- 指针操作问题,请高手指点!
...
Select * from Mytable where MyDate like ''%+ls_date+%''
...
coun:=*.recordcount;
在Delphi5自带的Local SQL Help里有。
应该能解决你的问题。
select count(MyID) from MyTable
where EXTRACT(MONTH FROM MyDate) = 6
select myid,count(*) from 表名 where mydate>:变量1 and mydate<:变量2
select myid,
c01=case day(mydate) when 1 then count(myid) end,
c02=case day(mydate) when 2 then count(myid) end,
c03=case day(mydate) when 3 then count(myid) end,
c04=case day(mydate) when 4 then count(myid) end,
c05=case day(mydate) when 5 then count(myid) end,
c06=case day(mydate) when 6 then count(myid) end,
.
.
.
c31=case day(mydate) when 31 then count(myid) end,
total = count(myid) //总数
from tablename
where (year(mydate)=2001) and (month(mydate)=6)
GROUP BY myid//把它写到存储过程中来计算汇总数很方便
//语句的执行效率我不知道怎么样
比如没有31日,那c31没有数据就是了。把我上面的查询写到存储过程中,
先把查到的每日列表数据存到临时表中,
然后对该临时表进行汇总、统计处理,
什么样的统计基本上应该都可以解决的。======================//判断日期间的天数:declare @da1 datetime
declare @da2 datetimeselect @da1='2001-06-01'
select @da2='2001-07-01'select DATEDIFF(day,@da1,@da2) ---输出30select @da1=@da2
select @da2='2001-08-01'select DATEDIFF(day,@da1,@da2) ---输出31go
这样就可以得出6月份平均每天的个数,但是这要求每天都至少有一条记录,
如果Mytable可以满足这样就可以了,否则可能还有点问题
create proc getmonthnum @y int,@m int,@n int out
as
select @n=datediff(day,cast(@y as varchar(4))+'-'+cast(@m as varchar(2))+'-1',dateadd(month,1,cast(@y as varchar(4))+'-'+cast(@m as varchar(2))+'-1'))
使用举例:declare
@y varchar(4),@m varchar(2),@n int
select @y='2000',@m='2'
exec getmonthnum @y,@m,@n out
select @n
group by myid,mydatep_date1=strtodate(format('%s-%s-01',edit1,edit2)//format的具体用法请查书
p_date1=strtodate(format('%s-%s-01',edit1,inttostr(strtoint(edit2)+1))
所需的数目就是查询的记录数。
p_date1=strtodate(format('%s-%s-01',edit1,edit2)//format的具体用法请查书
p_date2=strtodate(format('%s-%s-01',edit1,inttostr(strtoint(edit2)+1))
所需的数目就是查询的记录数。
我不知道你要的是不是这东西,如果要给我mial.我给发过去,---注:该函数不是我写的,是另一个同事写的。--其实也很简单的,大家可以试着自己去编编看。haha a fasdfdsfsdfsdfsd
sdfsd
af
sdf
sd
f
1.Select count(distinct MyId) from Mytable where MyDate='2001-6-1'
Select count(distinct MyId) from Mytable where MyDate='2001-6-2'
......
Select count(distinct MyId) from Mytable where MyDate='2001-6-30'
怎样做一个通用过程求以上30条语句的查询结果之和。
2.给出年份和月份,在Delphi(也可以在SQLServer)中通过一个通用过程知道这个月的天数呢?
1. SELECT * FORM YOURTABLE WHERE myday<'xxx' and mydate>'xxx' 到tquery 然后
2. 读取 Tquery1.recoderset.count不就可以拉?何必一条条SELECT?
query1.active := false;
query1.sql.clear;
query1.parambyname('qssj').asstring := edit1.text;//qssj为起始时间
query1.parambyname('zzsj').asstring := edit2.text;
query1.sql.add('Select count(distinct MyId) from Mytable where MyDate> :qssj and MyDate<:zzsj');
query1.execsql;
query1.active := true;
这样就灵活了