| |

VerySource

 Forgot password?
 Register
Search
View: 9|Reply: 3

Find a SQL

[Copy link]

1

Threads

1

Posts

2

Credits

Newbie

Rank: 1

Credits
2

 China

Post time: 2020-3-18 20:00:01
| Show all posts |Read mode
There is a table as follows
num1 num2 date
  1 2 20160329
  1 2 20160329
  1 2 20160329
  1 2 20160330
  1 2 20160401
...

Now I want to write a query to find the sum of num1 and num2 every 7 days. Please ask everyone to write a Sql and explain the idea.
Reply

Use magic Report

1

Threads

7

Posts

5

Credits

Newbie

Rank: 1

Credits
5

 China

Post time: 2020-7-16 11:45:01
| Show all posts
Every 7 days, do you mean 7 days a month, or any 7 days?
Reply

Use magic Report

0

Threads

1

Posts

2

Credits

Newbie

Rank: 1

Credits
2

 China

Post time: 2020-7-16 19:45:01
| Show all posts
Table partitions are summarized, and the granularity of the summary is based on the amount of data every 7 days
Reply

Use magic Report

0

Threads

1

Posts

2

Credits

Newbie

Rank: 1

Credits
2

 China

Post time: 2020-7-27 03:00:01
| Show all posts
select sum(num1), sum(num2) where datediff(date1, date2)=7

date1, date2 are two dates
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2020|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list