Home > database >  Master [into] how statistics with many times into the detailed data with the customers
Master [into] how statistics with many times into the detailed data with the customers

Time:11-19



As shown, strives for the statistics of the results of the SQL statement, gave high marks

CodePudding user response:

This obviously not ah,
Zhang SAN, li si, fifty and fighter on the same day, how can appear this kind of result?

The demand to ask clear.

CodePudding user response:

Have the same with, certainly feasible, but it is not a date type, should be a datetime types,
Your results table, is a set of parallel data, it can't statistics,

CodePudding user response:

reference 1st floor shoppo0505 response:
this apparent wrong ah,
Zhang SAN, li si, fifty and fighter on the same day, how can appear this kind of result?

The demand to figure out what to ask again,

Buddy list did not understand oh

CodePudding user response:

The
Quote: refer to the original poster weixin_41616098 response:



As shown, strives for the statistics of the results of the SQL statement, gave high marks [/quote
Oh is a datetime type

CodePudding user response:

 IF the EXISTS (SELECT * FROM TEMPDB for.. SYSOBJECTS WHERE ID=OBJECT_ID (' TEMPDB for.. # # ')) data source DROP TABLE data 
Create table # (data source name nvarchar (10), a datetime in time, datetime, check-out time days int)

Insert into # (data source name, in time, departure time, number of days)
Select 'zhang', '2020-05-01', '2020-05-05', 5 union all
Select 'bill', '2020-05-01', '2020-05-05', 5 union all
Select 'Cathy', '2020-05-01', '2020-05-05', 5 union all
Select 'zhang', '2020-06-01', '2020-06-05', 5 union all
Select 'Cathy', '2020-06-01', '2020-06-05', 5


With cte as (
The select ROW_NUMBER () over (partition by a. occupancy time, a. departure time order by a. name) as Id, # * from the data source as a
)
In time, name, select a. a. a. departure time, a. days, b. name as the name 1, b. in time as in 1 time, b. 1 as departure time of your departure time, b. days as number 1
The from cte join a cte on a. b in time=b. in time and a. departure time=b. departure time and Anderson, d! B.I=d where Anderson, d=1
/*
Zhang SAN 2020-05-01 00:00:00. 000 2020-05-05 00:00:00. 000 5 li si 2020-05-01 00:00:00. 000 5 000 2020-05-05 00:00:00.
Zhang SAN 2020-05-01 00:00:00. 000 2020-05-05 00:00:00. 000 5 fifty 2020-05-01 00:00:00. 000 5 000 2020-05-05 00:00:00.
Zhang SAN 2020-06-01 00:00:00. 000 2020-06-05 00:00:00. 000 5 fifty 2020-06-01 00:00:00. 000 2020-06-05 00:00:00. 5 * 000/
  • Related