重复的问题
是否可以在使用Codeigniter Mysql的单个查询中使用codeigniter获得此输出?
oid | count(waiters) as total_waiters
----+-------------------------------
1 | 1 <-- john will be count as 1 even if assigned to 2 room
2 | 1
3 | 2 <-- count is 2 because different waiters are assigned with different room
4 | 0
订单表
oid | name
----+-------
1 | aa
2 | bb
3 | cc
4 | dd
房间桌子
Rid | oid | waiter_assigned
----+-------+-----------------
1 | 1 | john
2 | 1 | john
3 | 2 | john
4 | 3 | mike
5 | 3 | dude
我尝试使用工会
$this->db->select('o.oid,"" AS tot_book_thera');
$this->db->from('order o');
$query1 = $this->db->get_compiled_select();
$this->db->select('r.oid,count(r.waiter_assigned) AS total_waiters');
$this->db->from('room r');
$this->db->group_by('r.waiter_assigned');
$query2 = $this->db->get_compiled_select();
但是我明白了...
oid | count(waiters) as total_waiters
----+-------------------------------
1 | 1
2 | 1
3 | 2
1 | '' <-- not sure how to combine it with the 1st or how to exclude this or remove this...
非常感谢任何帮助,谢谢大家!