2013-05-31 27 views
-2

比較兩個布爾值時可以使用操作數嗎?在BOOL(tinyint(1))上使用OR操作數字段MYSQL

使用MYSQL 5+

Ex。

ON DUPLICATE KEY UPDATE 
table1.3_InMarket = (table1.3_InMarket OR b.3_InMarket), 

我想設置True值到該字段,如果新舊之間存在。

這兩個字段都設置爲tinyint(1)aka布爾。

+0

您是否閱讀過手冊? – Kermit

+0

你知道'ON DUPLICATE KEY UPDATE'是插入語句的一部分嗎?它並不孤單。 –

+0

是的,是的。我不想分享我的所有代碼:p 我使用SELECT TRUE OR FALSE對其進行了測試;它似乎工作。只想要第二個opionon。 –

回答

2

您可以使用一個簡單的表格測試行爲。

drop table test; 
create table test (
    n integer not null, 
    tf boolean not null default false, 
    primary key (n) 
); 
-- Starts false, set to true. 
insert into test values (1, false); 
insert into test values (1, false) on duplicate key update tf = (tf or true); 
-- Starts false, does not set to true. 
insert into test values (2, false); 
insert into test values (2, false) on duplicate key update tf = (tf or false); 
-- Starts true, set to true. 
insert into test values (3, true); 
insert into test values (3, true) on duplicate key update tf = (tf or true); 
-- Starts true, does not set to false. 
insert into test values (4, true); 
insert into test values (4, true) on duplicate key update tf = (tf or true); 

select * from test; 
+0

謝謝,測試了這一點 –

0

這是值得檢查的,以便您更好地瞭解它作爲開發人員,但這應該是完全可能的。

相關問題