我有一个要执行的MySQL任务表,每行都有一个任务的参数.
有许多工作者应用程序(可能在不同的机器上),在循环中执行任务.
应用程序使用MySQL的本机C API访问数据库.
为了拥有一个任务,一个应用程序做了类似的事情:
生成全局唯一ID(为简单起见,假设它是一个数字)
UPDATE tasks
SET guid = %d
WHERE guid = 0 LIMIT 1
SELECT params
FROM tasks
WHERE guid = %d
如果最后一个查询返回一行,我们拥有它并让参数运行
有没有办法在一次调用服务器时实现相同的效果(即'拥有'一行并获取其参数)?
我想实现以下目标:
表的当前状态(my_table)
id totalX totalY totalZ
--------- -------------- -------------- --------------
9 34 334 0
10 6 56 0
11 21 251 0
12 3 93 0
Run Code Online (Sandbox Code Playgroud)
查询结果(my_table2)
select id,count(*) as total FROM my_table2 WHERE column_2 = 1 GROUP BY id
id total
--------- --------------
9 500
10 600
11 700
12 800
Run Code Online (Sandbox Code Playgroud)
表的预期状态(my_table)
id totalX totalY totalZ
--------- -------------- -------------- --------------
9 34 334 500
10 6 56 600
11 21 251 700
12 3 93 800
Run Code Online (Sandbox Code Playgroud)
这可以在一个更新查询中完成吗?我在RHEL 5.0上寻找Sybase ASE …
是否有一个查询可以同时进行两个查询?
这是第一个
$q = "select c.id as campaignId,c.priceFactor,
o.cid,o.bloggerPrice,o.state as state,o.customerPrice,o.id as orderId,o.listPrice,o.basicPrice
from campaign c, orders o
where c.id={$campaignId}
and c.id = o.cid
and o.state in (8,9)";
Run Code Online (Sandbox Code Playgroud)
这是第二个
foreach($orders as $order)
{
$listPrice = $order->priceFactor * $order->basicPrice;
if($order->bloggerPrice < $listPrice || $order->customerPrice < $listPrice)
{
$order->bloggerPrice = $listPrice;
$order->customerPrice = $listPrice;
}
$qUpdate = "update orders set
listPrice = {$listPrice},bloggerPrice={$order->bloggerPrice},
customerPrice ={$order->customerPrice}
where id=$order->orderId and cid={$order->cid}";
// $this->db->q($qUpdate);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:如果没有纯PHP的PHP代码,是否可以完成上述操作?