目前,这是我的 php 脚本:
$users = DB::select('id', 'email', 'firstname', 'lastname')->from('users')->execute()->as_array();
$orders = array();
foreach($users as $user)
{
$anyOrder = DB::select('id')->from('orders')
->where('orders.date_created', 'BETWEEN', array($from, $to))
->and_where('orders.user_id', '=', $user['id'])
->and_where_open()
->and_where('orders.status', '=', 'new')->or_where('orders.status', '=', 'delivered')
->and_where_close()
->execute()->count();
if($anyOrder == 0)
{
$orders[] = array('firstname' => $user['firstname'], 'lastname' => $user['lastname'], 'email' => $user['email']);
}
}
(DB::select() 是一个查询,我使用的是 kohana 查询生成器)。
这很好用,直到现在我有超过数千名用户。
如何简化和更快地做到这一点?
该脚本所做的是将所有在 $from 和 $to 之间没有订单的人保存到 $orders 数组中。