About the use of approximately equal values for an SQL statement

Source: Internet
Author: User

There is a standard table T1, field F1, F2

Example: 100 3

200 9

300 28

 

There is a list below, T2, only one field F1,

Example: 110

180

230

Take the lowest standard value and the final result is

110 3

180 3

230 9

After thinking for a long time, I made an SQL statement:

Select CZ. f1, BZ. f2 from (select t2.f1, min (t2.f1-t1.f1) as C from T2, T1 where t2.f1> t1.f1 group by t2.f1) CZ left join T1 BZ on (CZ. f1-cz.c) = BZ. f1

Currently, the test data is correct. I don't know if it is true or not. Is there any better way?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.