當前位置:首頁 » 編程語言 » sql不同時段人數
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql不同時段人數

發布時間: 2022-06-09 18:17:06

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