更新时间:2023-11-21 15:56:40
只是试试这个,让我知道,
Just try this one and let me know,
$this->db->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", FALSE );
$this->db->from('orderTB a');
$this->db->join('productTB b','a.id_product = b.id_shirt','inner');
$this->db->join('sizeTB c','a.id_size = c.id_size','inner');
$this->db->group_by('b.name');
从文件这里
$这个 - > DB->选择()接受一个可选的第二个参数。如果设置 它为FALSE,codeIgniter不会尽力保护你的领域或表 名与反引号。如果你需要一个化合物的选择,这非常有用 声明。
$this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement.
修改
只需添加 FALSE
在你的SELECT语句
Just add FALSE
in your select statement
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",FALSE);
$this->db->from('order');
$this->db->join('ukuran','order.id_size=ukuran.id_size');
$this->db->where('date',$date);
return $this->db->get();
}