① sql 计算一个时间段内的总人数如11:00-11:15这个时间段内的人数,新手求指教
select sum(num) from person where time between 11:00 and 11:15
查询方法可以用上面的,但是你的时间格式是不是有问题哦
② SQL查询各时间段的挂号人数
如果是指8点到17点之外其他时间点的人数,这样行不行:
SELECT datepart(hour,ghsj)as 挂号时间, count(*) as 人数
FROM GH_MZLSB
WHERE ( GH_MZLSB.THBZ = '0' ) and (DATEPART(year,GHSJ)=2010
and DATEPART(month,GHSJ)=10
and DATEPART(day,GHSJ)=8)
and (datepart(hour,ghsj) between 18 and 23 or datepart(hour,ghsj) between 0 and 7)
group by datepart(hour,ghsj)
order by datepart(hour,ghsj)
③ 利用SQL语句统计出各年龄段人数
select '25-30岁' as 年龄段 count(*) as 人数 from tb where year(getdate())-year(birthday)>=25 and year(getdate())-year(birthday)<30
union all
select '30-35岁' as 年龄段 count(*) as 人数 from tb where year(getdate())-year(birthday)>=30 and year(getdate())-year(birthday)<35
union all
select '35-40岁' as 年龄段 count(*) as 人数 from tb where year(getdate())-year(birthday)>=35 and year(getdate())-year(birthday)<40
④ sql中按不同字段统计数量的查询语句,要求在一个时间段中
//thinkphp5.1查询7天内每天的金额总数
$dates=[];
for($i=7;$i>=0;$i--){//近7天日期
$dates[]=date('Y-m-d',strtotime('-'.$i.'days'));
}
$where="whereunix_timestamp(time)>=unix_timestamp('".$dates[0]."')";
$order="groupbydate_format(time,'%Y-%m-%d')";
$select="selectdate_format(time,'%Y-%m-%d')astime,sum(money)ascountfromczjl";
$sql=$select.$where.$order;
$orderList=Db::query($sql);
mp($orderList);
你可以参考下
⑤ sql语句 怎么统计各年龄段人数分布情况 年龄为user_age,表为worker,年龄已知为数字类型
selectuser_age年龄,count(user_age)人数,cast(cast((count(user_age)/((selectcount(*)fromworker)*1.0)*100)asdecimal(9,2))asvarchar)+'%'所占比例fromworkergroupbyuser_age
⑥ sql数据库中多时间段查询并统计,查询语句怎么写
--两出生时段人数统计:
select count(*) from(select name from 你的表名 where 出生日期 between '1992-01-01'and'1992-01-12'union select name from 你的表名 where 出生日期 between '1992-01-13'and'1992-01-20')
⑦ sql 同时统计各个时间段内的次数
假设表结构是
使用人id:int 使用时间:datetime
那么可以这么写sql:
select datepart(hh,使用时间) 时间段,count(使用人id) 使用人数 from 表名 group by datepart(hh,使用时间)
⑧ 查询某一段时间内的总人数,用SQL语句
select sum(人数栏位) from 表名 where 时间栏位 between '日期1'and '日期2'
⑨ sql如何查出各段时间数据数
SELECT T.COMPANYNAME 公司名称,
COUNT(1) 人数,
COUNT(CASE
WHEN MONTHS_BETWEEN(SYSDATE, T.HIREDATE) <= 3 THEN
1
END) / COUNT(1) 入职三个月以下人数百分比,
COUNT(CASE
WHEN MONTHS_BETWEEN(SYSDATE, T.HIREDATE) > 3 THEN
1
END) / COUNT(1) 入职三个月以上人数百分比
FROM EMPLOYEE T
GROUP BY T.COMPANYNAME;
⑩ 关于sql2005中计算不同时间数量计算的问题
DECLARE @A INT
DECLARE @B INT
SELECT @A=MIN(ID) FROM TABLE
SELECT @B=MAX(ID) FROM TABLE
WHILE(@A<@B)
BEGIN
INSERT INTO #A
SELECT T1.TIME, (T1.SHU-T2.SHU) AS SHU FROM TABLE T1,TABLE T2
WHERE T1.ID=T2.ID+1 AND T2.ID=@A
SET @A=@A+1
END
SELECT * FROM #A