SQL Interview question: there is a B C three column, implemented with SQL statement: When column A is greater than column B, select column B otherwise

Source: Internet
Author: User

Ask a query question for an SQL statement that was encountered during an interview
The table has a B C three column, implemented with the SQL statement: When column A is greater than column B, select column B, or column B if column B is greater than column C, select column C otherwise.
------------------------------------------
Select (case if A>b then a else B end),
(case is b>c then B esle C end)
From table_name

[SQL]View PlainCopy
    1. Drop Table table1
    2. Create table table1 (
    3. A int,
    4. b int,
    5. C int
    6. )
    7. INSERT INTO table1 values (22,24,23)
    8. SELECT * FROM table1
    9. Select (case is a>b then a else B end), (case isb>c then b else C end)
    10. From table1
    11. Select (case if a>b then a
    12. When A>c then a
    13. When b>c then b else C
    14. end)
    15. From table1

SQL Interview question: there is a B C three column, implemented with SQL statement: When column A is greater than column B, select column B otherwise

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.