如何使用$ this-> db编写下面的sql查询

时间:2014-09-15 04:27:03

标签: mysql codeigniter

SELECT Shippers.ShipperName,COUNT(Orders.OrderID) AS NumberOfOrders FROM Orders
LEFT JOIN Shippers
ON Orders.ShipperID=Shippers.ShipperID
GROUP BY ShipperName; 

2 个答案:

答案 0 :(得分:0)

你可以尝试这个:

$this->db->select('Shippers.ShipperName,COUNT(Orders.OrderID) AS NumberOfOrders');
$this->db->join('Shippers', 'Orders.ShipperID = Shippers.ShipperID', 'left');
$this->db->group_by('ShipperName');
$getResult=$this->db->get('ShipperName');

答案 1 :(得分:0)

试试这个:

$this->db
    ->select('b.ShipperName, count(a.OrderID) as NumberOfOrders')
    ->join('Shippers b', 'b.ShipperID = a.ShipperID', 'left')
    ->group_by('b.ShipperName')
    ->get('Orders a')->result_array();