| |

VerySource

 Forgot password?
 Register
Search
View: 1131|Reply: 7

A simple question about dates?

[Copy link]

3

Threads

10

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-2-6 21:00:01
| Show all posts |Read mode
The table is as follows:
id
2017-1-1
2017-1-4
2017-1-9
...

Find the nearest 2 records of a record

For example: 2017-1-4

Previous 2017-1-1
Next 2017-1-9

If it is the last or first record, give a prompt respectively.
Reply

Use magic Report

0

Threads

49

Posts

35.00

Credits

Newbie

Rank: 1

Credits
35.00

 China

Post time: 2020-3-26 17:00:01
| Show all posts
What is the "closest" criterion?

2017-1-1
2017-1-3
2017-1-4
2017-1-9

For such data, which two of 2017-1-4 should be the closest?
Reply

Use magic Report

0

Threads

66

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-3-26 17:30:02
| Show all posts
select top 1 * from t order by datediff (day, '2017-1-4', id)
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-3-26 21:00:01
| Show all posts
select id = identity (int, 1,1), a. * into #a from tablename a
It is more convenient to check from the temporary table.
Reply

Use magic Report

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 China

Post time: 2020-3-26 23:00:02
| Show all posts
Previous
select max (id) from tablename where id <'2017-1-4'
next
select min (id) from tablename where id> '2017-1-4'
Reply

Use magic Report

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 China

Post time: 2020-3-27 06:00:01
| Show all posts
Previous
select distinct max (id) from tablename where id <'2017-1-4' order by id
next
select distinct min (id) from tablename where id> '2017-1-4' order by id
Reply

Use magic Report

3

Threads

10

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-4-7 01:45:01
| Show all posts
Should be less than / greater than
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-4-8 10:15:01
| Show all posts
cv4bf5d65fdis creative.
Reply

Use magic Report

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

Points Rules

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

Quick Reply To Top Return to the list