确定我是否应该合并的案例声明 [英] Case statement to determine if I should union
本文介绍了确定我是否应该合并的案例声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前想做某种条件联合.给出以下示例:
I currently want to do some sort of conditional union. Given the following example:
SELECT age, name
FROM users
UNION
SELECT 25 AS age, 'Betty' AS name
说我想只在'users'的数量> = 2时才合并第二个语句,否则不要将两者合并.
Say I wanted to only union the second statement if the count of 'users' was >=2 , otherwise do not union the two.
总而言之,如果表仅具有2个或更多值,我想在表后附加一行.
In summary I want to append a table with a row if the table only has 2 or more values.
推荐答案
You could use an ugly hack something like this, but I think Tim's answer is better:
SELECT age, name
FROM users
UNION ALL
SELECT 25 AS age, 'Betty' AS name
WHERE (SELECT COUNT(*) FROM users) > 1
这篇关于确定我是否应该合并的案例声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文