SELECT Shippers.ShipperName,COUNT(Orders.OrderID) AS NumberOfOrders FROM Orders
LEFT JOIN Shippers
ON Orders.ShipperID=Shippers.ShipperID
GROUP BY ShipperName;
答案 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();