我试图找到一分钟内创建的最大记录数,我可以用java程序来做,但我想知道是否可以用sql查询完成
例如,在下面的数据中,使用分钟创建的最大记录数18
位于2016-03-14 18:22
分钟
ID CreatedAt
3197912 2016-03-14 18:23:38.930
3197911 2016-03-14 18:23:34.857
3197910 2016-03-14 18:23:34.847
3197909 2016-03-14 18:23:16.587
3197908 2016-03-14 18:23:14.937
3197907 2016-03-14 18:23:11.617
3197906 2016-03-14 18:23:00.013
3197905 2016-03-14 18:22:59.840
3197904 2016-03-14 18:22:54.453
3197903 2016-03-14 18:22:51.017
3197902 2016-03-14 18:22:37.893
3197901 2016-03-14 18:22:35.147
3197900 2016-03-14 18:22:29.437
3197899 2016-03-14 18:22:27.383
3197898 2016-03-14 18:22:23.897
3197897 2016-03-14 18:22:22.227
3197896 2016-03-14 18:22:20.890
3197895 2016-03-14 18:22:19.317
3197894 2016-03-14 18:22:18.063
3197893 2016-03-14 18:22:15.447
3197892 2016-03-14 18:22:08.693
3197891 2016-03-14 18:22:04.927
3197890 2016-03-14 18:22:01.417
3197889 2016-03-14 18:22:00.637
3197888 2016-03-14 18:22:00.283
3197887 2016-03-14 18:21:59.597
3197886 2016-03-14 18:21:56.713
3197885 2016-03-14 18:21:56.677
3197884 2016-03-14 18:21:56.640
3197883 2016-03-14 18:21:56.603
3197882 2016-03-14 18:21:56.570
3197881 2016-03-14 18:21:56.537
3197880 2016-03-14 18:21:55.687
3197879 2016-03-14 18:21:51.543
3197878 2016-03-14 18:21:49.730
3197877 2016-03-14 18:21:47.340
3197876 2016-03-14 18:21:46.590
3197875 2016-03-14 18:21:40.293
3197874 2016-03-14 18:21:34.993
3197873 2016-03-14 18:21:29.563
3197872 2016-03-14 18:21:18.043
3197871 2016-03-14 18:21:16.490
3197870 2016-03-14 18:21:13.827
3197869 2016-03-14 18:21:00.783
3197868 2016-03-14 18:20:46.100
有人可以帮我这个吗?
答案 0 :(得分:1)
select cast(dt as date), datepart(hh, dt), datepart(mm, dt), datepart(ss,dt)
, count(*)
from table
group by cast(dt as date), datepart(hh, dt), datepart(mm, dt), datepart(ss,dt)
order by count(*) desc
答案 1 :(得分:1)
select TOP 1 myID,DateWithMinute from
(select count(ID) as myID,convert(varchar(16),createdat,120) as DateWithMinute
from yourtable
group by convert(varchar(16),createdat,120)
order by count(ID) desc)