Home > database >  SQL statements problem
SQL statements problem

Time:10-09

A table
Position id name date
1 A aa - 1
2 B bb - 1
3 C cc - 1
4 A aab 1-2
5
6

Structure as shown in the above:

When the date update on January 1, January 2, A corresponding name update aab will have to remain the same problems that didn't update in the database to the
I want to find out 1 to 2 corresponding to the three position data to SQL found out how to use the

The way I take now whether or not the name of ABC changes every day together in the database but it's also changes every day so workload too big name

Can store only changes the name does not change by the SQL statement added

CodePudding user response:

Save time use the merge into, judge range name when insert - & gt; Only in the update name
Query using row_number function, apply from the date of the query to recent data, such as check 1-2 data, grouped according to the location, date, pick up the latest date,
According to the above example, will take to the aab, A and B will take to BB, will take to CC, C, query write A date can be classified as constant - & gt; The query is always the latest

Merge into reference articles:
https://blog.csdn.net/jeryjeryjery/article/details/70047022
Group functions can refer to the article:
https://blog.csdn.net/qq_41805514/article/details/81772182

CodePudding user response:

reference 1/f, sun flower reply:
save time, use the merge into judgment range name when insert - & gt; Only in the update name
Query using row_number function, apply from the date of the query to recent data, such as check 1-2 data, grouped according to the location, date, pick up the latest date,
According to the above example, will take to the aab, A and B will take to BB, will take to CC, C, query write A date can be classified as constant - & gt; The query is always the latest

Merge into reference articles:
https://blog.csdn.net/jeryjeryjery/article/details/70047022
Group functions can refer to the article:
https://blog.csdn.net/qq_41805514/article/details/81772182


Ok thank you I look at first
  • Related