Count the most profitable information on a daily basis

Source: Internet
Author: User
-- User Betting table History Table
Create table t_Userinfo_his (
Rid int identity,
Userid int not null, -- User ID
Nick varchar (50) not null, -- user nickname
Termid int not null, -- competition ID
Nums int not null, -- bet number
Instone bigint not null, -- input amount
Outstone bigint not null, -- return amount
Addtime datetime not null, -- bet time
)
Go

-- Function: Count the most profitable users on a daily basis
-- Author: Tester
-- Creation date:
Create procedure p_daystar
@ Date datetime -- start from which day
As
Set nocount on
Set transaction isolation level read uncommitted
Set xact_abort on
-- Create a table variable to store the user ID, total profit of the user on the current day, and date
Declare @ tb table (userid int, outstone bigint, addtime char (10 ))
Insert @ tb select userid, sum (outstone) as outstone, convert (char (10), addtime, 20) as addtime from t_userinfo_his with (nolock)
Where convert (char (10), addtime, 20)> = @ date
Group by userid, convert (char (10), addtime, 20)
-- Select * from @ tb
Select addtime, max (outstone) as outstone, userid = (select userid from @ tb where addtime = a. addtime and outstone = max (a. outstone) from @ tb as
Group by addtime
Go

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.