正在做一个消费统计的程序,要求查询指定日期内所有人的消费次数,但是同一天内的消费记录不管有几次都只算作一次,就是说某人某日早中晚吃了三餐,但是只能算一次
表名:xf_times
empid,actdatetime,money
0001,2012-06-01 07:49:51,3
0001,2012-06-01 12:01:23,8
0001,2012-06-01 17:32:02,6.5
求SQL语句,急
急问sql server按日期查询次数合计
答案:2 悬赏:0 手机版
解决时间 2021-03-05 15:18
- 提问者网友:捧腹剧
- 2021-03-05 01:50
最佳答案
- 五星知识达人网友:不如潦草
- 2021-03-05 02:51
创建个视图 将时间分割成3个字段 Y M D
然后对这3个字段分组
如
create view viewName
as (select empid,year(actdatetime),month(actdatetime),day(actdatetime) from xf_times
go
select count(empid) ,y,m,d from viewName group by y,m,d
go
sqlserver 2005测试通过
然后对这3个字段分组
如
create view viewName
as (select empid,year(actdatetime),month(actdatetime),day(actdatetime) from xf_times
go
select count(empid) ,y,m,d from viewName group by y,m,d
go
sqlserver 2005测试通过
全部回答
- 1楼网友:走死在岁月里
- 2021-03-05 03:00
what are two methods of retrieving sql? what cursor type do you use to retrieve multiple recordsets? what is the difference between a “where” clause and a “having” clause? - “where” is a kind of restiriction statement. you use where clause to restrict all the data from db.where clause is using before result retrieving. but having clause is using after retrieving the data.having clause is a kind of filtering command. what is the basic form of a sql statement to read data out of a table? the basic form to read data out of table is ‘select * from table_name; ‘ an answer: ‘select * from table_name where xyz= ‘whatever’;’ cannot be called basic form because of where clause. what structure can you implement for the database to speed up table reads? - follow the rules of db tuning we have to: 1] properly use indexes ( different types of indexes) 2] properly locate different db objects across different tablespaces, files and so on.3] create a special space (tablespace) to locate some of the data with special datatype ( for example clob, lob and …) what are the tradeoffs with having indexes? - 1. faster selects, slower updates. 2. extra storage space to store indexes. updates are slower because in addition to updating the table you have to update the index.
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯