誰でもこのクエリをアクティブ レコードの codeigniter に変換できますか???
SELECT b.name,
SUM(CASE WHEN c.size = 'S' THEN 1 ELSE 0 END) S,
SUM(CASE WHEN c.size = 'M' THEN 1 ELSE 0 END) M,
SUM(CASE WHEN c.size = 'L' THEN 1 ELSE 0 END) L,
SUM(CASE WHEN c.size = 'XL' THEN 1 ELSE 0 END) XL
FROM orderTB a
INNER JOIN productTB b
ON a.id_product = b.id_shirt
INNER JOIN sizeTB c
ON a.id_size = c.id_size
GROUP BY b.name
私はこのように試しました
function get()
{
$this->db->select("b.name,SUM(CASE WHEN c.size ='S' THEN 1 ELSE 0 END) as S,SUM(CASE WHEN c.size = 'M' THEN 1 ELSE 0 END) as M,SUM(CASE WHEN c.size = 'L' THEN 1 ELSE 0 END) as L,SUM(CASE WHEN c.size = 'XL' THEN 1 ELSE 0 END) as XL");
$this->db->from('order');
$this->db->join('ukuran','order.id_size=ukuran.id_size');
$this->db->where('date',$date);
return $this->db->get();
}
しかし、それは間違っています