问题描述
我遇到整数错误,但不明白为什么。
警告:#1292截断了错误的INTEGER值:'%accepted%';
警告:#1292截断了错误的INTEGER值:'%pending%'。
有人可以帮忙吗?
void activate(computer_t* comp)
{
comp->active = 1;
comp->timer = 100;
}
void* timerFunction(void* args)
{
struct timespec ts;
// Sleep interval before checking database again
ts.tv_sec = 1;
ts.tv_nsec = 0;
while(1)
{
// ************* LOCK *************
pthread_mutex_lock(&mutex);
/**
* Go through every database index
*/
for (int index = 0; index < NUM_COmpuTER; index++)
{
if (database[index].active)
{
if (database[index].timer > 0)
{
database[index].timer--;
}
else
{
/**
* Clean up database index
*/
memset(database + index,sizeof database);
}
}
}
// ************* UNLOCK *************
pthread_mutex_unlock(&mutex);
/**
* Sleep 1 sec before checking database again
*/
nanosleep(&ts,NULL);
}
}
解决方法
OrderStatus LIKE '%processing%' OR '%pending%' OR '%accepted%'
这不符合您的想法。 MySQL将其理解为:
(OrderStatus LIKE '%processing%')
OR ('%pending%')
OR ('%accepted%')
因此,它尝试在布尔上下文中评估字符串,这会产生警告,提示您。
您需要为每个匹配的字符串重复like
表达式:
(
OrderStatus LIKE '%processing%'
OR OrderStatus LIKE '%pending%'
OR OrderStatus LIKE '%accepted%'
)
或者您可以使用正则表达式:
OrderStatus RLIKE 'processing|pending|accepted'
请注意,这些条件应属于where
子句,而不是having
子句,因为它们与未聚合的列有关。我将查询短语表达为:
select
t1.post_id,t2.name,-- no need for an "else" branch here
max(case when meta_key = 'value' then meta_value end) as email
from table_1 t1
inner join table_2 t2 on find_in_set(t1.post_id,t2.payment_ids)
where
-- filtering in the "where" clause
OrderStatus rlike 'processing|pending|accepted' -- regex
and DeliveryDate >= current_date - interval 7 day -- no need for "datesub()"
and DeliveryType = 'pickup'
group by
-- all non-aggregated column in the `group by` clause
t1.post_id,t2.name
请注意,您应在查询中的 all 列前添加它们所属的表,以使代码清晰且不言自明。
,SELECT a.`post_id`,b.`name`,MAX(case when meta_key = 'value' THEN `meta_value` ELSE NULL END) as 'Email',FROM table_1 a
INNER JOIN table_2 b
ON FIND_IN_SET(a.post_id,b.payment_ids)
GROUP BY a.post_id
HAVING OrderStatus LIKE '%processing%' OR OrderStatus LIKE '%pending%' OR OrderStatus LIKE '%accepted%' AND DeliveryDate >= (DATE_SUB(CURDATE(),INTERVAL 7 DAY)) AND DeliveryType = 'pickup'