Reputation: 4034
I have a database table Tb1 with n columns and m count of rows.
Tb1 ======================================== field_0... field_k... field_p... field_n
Here is the pseudo-code that I need to express in SQL
if(count(select distinct Tb1.field_k) > 1) return "string_literal" else return Tb1.field_p
The result set should have m count of rows.
Upvotes: 0
Views: 79
Reputation: 432260
SELECT
CASE
WHEN x.testcase > 1 THEN "string_literal"
ELSE Tb1.field_p
END AS SomeCol
FROM
Tb1
CROSS JOIN
(
SELECT COUNT (DISTINCT Tb1.field_k) AS testcase
FROM Tb1
) x
Notes:
Upvotes: 2