Php 结果的if条件中的事件计划程序计数

Php 结果的if条件中的事件计划程序计数,php,mysql,events,triggers,scheduler,Php,Mysql,Events,Triggers,Scheduler,我有以下查询,我想更新数据库,如果计数是唯一的,即1。我已经在事件调度器mysql中创建了所有这些事件。但有些问题我无法确定。如果可能,请帮助我,查询如下: SELECT user_id, count(*) as cnt from auction_details a JOIN products p where p.product_id = a.product_id AND p.end_time ='2018-09-12 08:35:30' GROUP by bidprice order by b

我有以下查询,我想更新数据库,如果计数是唯一的,即1。我已经在事件调度器mysql中创建了所有这些事件。但有些问题我无法确定。如果可能,请帮助我,查询如下:

SELECT user_id, count(*) as cnt from auction_details a JOIN products p where p.product_id = a.product_id AND p.end_time ='2018-09-12 08:35:30' GROUP by bidprice order by bidprice

投标价格应是唯一的,以便在事件调度器中更新表格

我想在事件调度程序中执行此操作。我在事件计划程序中所做的工作如下:

DELIMITER |
DO
BEGIN 
DECLARE cnt AS INT;
SELECT user_id, count(*) as cnt from auction_details a JOIN products p where p.product_id = a.product_id AND p.end_time ='2018-09-12 08:35:30' GROUP by bidprice order by bidprice DESC LIMIT 1;    
IF cnt=1 THEN

SET @userid = SELECT user_id from auction_details a JOIN products p where p.product_id = a.product_id AND p.end_time ='2018-09-12 08:35:30' GROUP by bidprice order by bidprice DESC LIMIT 1;    
update products p join auction_details a on a.product_id = p.product_id join users u on u.user_id = a.user_id set p.winner = @userid WHERE p.end_time ='2018-09-12 08:35:30';
END IF;    
结束| 定界符

预期输出应该从具有唯一计数(即1)的查询中获取用户id,并更新products表,并将获胜者设置为该用户id


您需要在条款中添加
,而不是
其中
,还需要
按用户id分组

SELECT user_id, count(*) as cnt 
from auction_details a 
JOIN products p 
  ON p.product_id = a.product_id 
  AND p.end_time ='2018-09-12 08:35:30' 
GROUP by user_id
order by user_id

您检测到了什么问题?向我们展示数据库模式、示例数据、当前和预期输出。请阅读,这里是学习如何提高问题质量和获得更好答案的好地方。我们需要当前和预期的样本数据output@JuanCarlosOropeza .. 正如您在预期输出上看到的那样。我想要最独特的bidprices用户id作为预期输出区赢家的更新。老兄,你还没有包括样本数据。就像你给我看一块蛋糕,告诉我这样做,但没有告诉我什么是关键。我在第二部分有问题。第二部分是什么意思?当mycnt结果1出现时,我想更新数据库。在本例中,2来自价格标签。我想要我的计数的唯一值阅读我上面的评论,我们需要样本数据和预期输出预期输出在上图中。