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
- Drop Table table1
- Create table table1 (
- A int,
- b int,
- C int
- )
- INSERT INTO table1 values (22,24,23)
- SELECT * FROM table1
- Select (case is a>b then a else B end), (case isb>c then b else C end)
- From table1
- Select (case if a>b then a
- When A>c then a
- When b>c then b else C
- end)
- 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