6

我想在 MySql 中做一个选择,它结合了几列......像这样的伪代码:

SELECT payment1_paid AND payment2_paid AS paid_in_full 
FROM denormalized_payments 
WHERE payment1_type = 'check';

编辑: payment1_paid 和 payment2_paid 是布尔值。

除了MySql,我不能使用任何其他语言来解决这个特定问题。

谢谢你的帮助!

编辑:对于所有给我求和和连接建议的人,我很抱歉,但我已经投票赞成那些早期的答案,因为它们无论如何都是有用的。感谢大家的快速回答!

4

7 回答 7

5

好的,为了合乎逻辑,你可以做

Select (payment1_paid && payment2_paid) as paid_in_full 
from denormalized_payments 
where payment1_type = 'check';

如此处所见。

于 2008-10-29T22:50:55.813 回答
2

做就是了

Select CONCAT(payment1_paid, payment2_paid) as paid_in_full 
from denormalized_payments 
where payment1_type = 'check';

您可以连接任意数量的字段。

于 2008-10-29T22:42:06.190 回答
2

如果通过组合你的意思是连接,那么这将起作用:

select concat(payment1_paid, payment2_paid) as paid_in_full
from denormalized_payments where payment1_type = 'check';

如果通过组合你的意思是添加,那么这应该工作:

select payment1_paid + payment2_paid as paid_in_full
from denormalized_payments where payment1_type = 'check';

[编辑]

对于布尔 AND:

select payment1_paid && payment2_paid as paid_in_full
from denormalized_payments where payment1_type = 'check';
于 2008-10-29T22:43:29.633 回答
1

我不确定,但你的意思是连接吗?

SELECT CONCAT(ColumnA, ColumnB) AS ColumnZ
FROM Table
于 2008-10-29T22:44:05.250 回答
1

SELECT IF(payment1_paid = 1 AND payment2_paid = 1, 1, 0) AS paid_in_fill

于 2008-10-29T22:46:51.530 回答
0

如果是字符串(或者您想将要组合的列视为字符串),您可以使用CONCATCONCAT_WS。祝你好运!

于 2008-10-29T22:48:58.593 回答
0
select (payment1_paid && payment2_paid) as paid_in_full
from denormalized_payments where payment1_type = 'check';
于 2008-10-29T23:12:35.723 回答