Scenario: In a database, you need to sort a result by a number of fields, sorted by a different weight, but the maximum weight of one field is limited to 30.
Analysis: There are no a>30?30:a operations in SQL, only basic operations (+-*/), logical operations (&& | | XOR) and so on.
Answer:
((a-a%30) &&1) *30:a less than 30 o'clock, a-a%30 is 0, (0&&1) *30 result is 0,a greater than or equal to 30 o'clock, the final result is 30
(a-a%30) XOR 1: When a is greater than or equal to 30 o'clock, the value is 0, less than 30 o'clock, and the result is 1
((A-A%30) XOR 1) * (A%30): When a is greater than or equal to 30 o'clock, the value is 0, less than 30 o'clock, the result is a
Final: ((a-a%30) &&1) *30+ ((a-a%30) XOR 1) * (A%30)
When a is less than 30 o'clock, a portion of the operation before the + number is 0, and the subsequent operation gets a, adding a
When a is greater than or equal to 30 o'clock, a part of the operation before the + number gets 30, and then the operation gets 0, and the sum is 30.
If you do not use a judgment operation to ensure that any number is greater than 30 or 30, otherwise the original value (the maximum limit on the field value when sorting in SQL)