你能帮我吗?
没有使用表
选择*订购方式 id
asc限制0
这是我在模型上的sql代码
private function _get_datatables_query()
{
$this->db->query("SELECT mainproduk.id,
mainproduk.barcode as barcod,
mainproduk.nama_produk,
mainproduk.nama_alias,
mainproduk.satuan,
mainproduk.produk_jadi,
mainproduk.kemasan,
mainproduk.min_stok_kemasan,
mainproduk.status,
mainproduk.top_item,
mainproduk.tipe_produk,
mainproduk.nomor_kemtan,
coalesce(sum(R.jumlah_pc),0) as omzet
FROM mainproduk
LEFT JOIN
(
SELECT id,barcode, jumlah_pc
FROM rincian_order WHERE tipe='po' AND status!='canceled' AND tanggal_kirim BETWEEN '$kemarins' AND '$blnkemarin'
) AS R
ON mainproduk.barcode = R.barcode WHERE status=1 GROUP BY mainproduk.id ORDER BY mainproduk.id ASC");
$i = 0;
foreach ($this->column_search as $item) // loop column
{
if($_POST['search']['value']) // if datatable send POST for search
{
if($i===0) // first loop
{
$this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
$this->db->like($item, $_POST['search']['value']);
}
else
{
$this->db->or_like($item, $_POST['search']['value']);
}
if(count($this->column_search) - 1 == $i) //last loop
$this->db->group_end(); //close bracket
}
$i++;
}
if(isset($_POST['order'])) // here order processing
{
$this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
}
else if(isset($this->order))
{
$order = $this->order;
$this->db->order_by(key($order), $order[key($order)]);
}
}
当我使用上述方法时会出现没有表格问题,因为录音是关闭的。
然后我用下面这样的活动记录更改它,并且有一个错误,似乎“coalesce”不支持这种格式,那么如果“coalesce(sum(details\u order.jumlah\u pc),0)as omzet”我删除它将显示如下错误
private function _get_datatables_query()
{
$this->db->select('mainproduk.barcode as barcod, mainproduk.nama_produk, mainproduk.nama_alias, mainproduk.satuan, mainproduk.produk_jadi, mainproduk.kemasan, mainproduk.min_stok_kemasan, mainproduk.status, mainproduk.top_item, mainproduk.tipe_produk, mainproduk.nomor_kemtan, coalesce(sum(rincian_order.jumlah_pc),0) as omzet')
->from('mainproduk')
->join('rincian_order', 'mainproduk.barcode = rincian_order.barcode', 'left')
->where('mainproduk.status =', 1)
->group_by('mainproduk.id')
->order_by('mainproduk.id', 'ASC');
$i = 0;
foreach ($this->column_search as $item) // loop column
{
if($_POST['search']['value']) // if datatable send POST for search
{
if($i===0) // first loop
{
$this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
$this->db->like($item, $_POST['search']['value']);
}
else
{
$this->db->or_like($item, $_POST['search']['value']);
}
if(count($this->column_search) - 1 == $i) //last loop
$this->db->group_end(); //close bracket
}
$i++;
}
if(isset($_POST['order'])) // here order processing
{
$this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
}
else if(isset($this->order))
{
$order = $this->order;
$this->db->order_by(key($order), $order[key($order)]);
}
}
order子句中的列“id”不明确
请帮忙
1条答案
按热度按时间axkjgtzd1#
与其他字段类似,请尝试将其作为语法编写。
如果这样不行,你能打印查询吗?