数据库中有一个消费记录表
字段有:user_id,bet_money等
查询测试语句:
SELECT COUNT(bet_money) AS Expr1
FROM lottery_bet
WHERE (user_id = '5557682') AND (DATEDIFF(dd, date_time, GETDATE()) = 0)
这个函数算出消费时间和当前时间的日差为0,说明为当天消费金额
count()函数统计出所有当日消费的金额
/// <summary> /// 获取用户当天的投注额 /// </summary> /// <returns>投注额</returns> public int getUserBet() { string sql = "select count([bet_money]) from [lottery_bet] where user_id=@user_id and DATEDIFF(dd,[data_time],DateTime.Now)=0"; manageDB manageDB = new manageDB(); return manageDB.getRecordQuantity(sql); }
public int getRecordQuantity(string sql) { int result = 0; try { this.openDB(); this.comm.CommandType = CommandType.Text; this.comm.CommandText = sql; result = (int)this.comm.ExecuteScalar(); } catch (Exception ex) { throw new Exception(ex.ToString()); } finally { this.closeDB(); } return result; }