型号:
$this->db->where('payment_details.created_on >= ',$start_date);
$this->db->where('payment_details.created_on <= ',$end_date);
$this->db->where('receipt_details.created_on >= ',$start_date);
$this->db->where('receipt_details.created_on <= ',$end_date);
$this->db->select('payment_details.id,payment_details.payment_no,payment_details.site_id,payment_details.vendor_id,payment_details.work,payment_details.description,payment_details.date,payment_details.amount,payment_details.tax_type,payment_details.tax,payment_details.subtotal,payment_details.grand_total,payment_details.created_on,receipt_details.id,receipt_details.receipt_no,receipt_details.site_id,receipt_details.vendor_id,receipt_details.work,receipt_details.description,receipt_details.date,receipt_details.amount,receipt_details.tax_type,receipt_details.tax,receipt_details.subtotal,receipt_details.grand_total,receipt_details.created_on,vendor.id,vendor.vname,site.id,site.sname');
$this->db->from('payment_details');
$this->db->join('vendor','vendor.id=payment_details.vendor_id OR vendor.id=receipt_details.vendor_id','LEFT');
$this->db->join('site','site.id=payment_details.site_id OR site.id=receipt_details.site_id','LEFT');
return $this->db->get()->result();
我会尝试但运行此查询时出错 错误: 错误号码:1064
您的SQL语法有错误;检查与您的MariaDB服务器版本对应的手册,以便在{LEFT JOIN vendor
ON vendor
附近使用正确的语法。id
= payment_details
。vendor_id
或者vendor
。“我在第2行
选择payment_details
。id
,payment_details
。payment_no
,payment_details
。site_id
,payment_details
。{{1} },vendor_id
。payment_details
,work
。payment_details
,description
。payment_details
,date
。payment_details
, amount
。payment_details
,tax_type
。payment_details
,tax
。payment_details
,subtotal
。payment_details
,{{ 1}}。grand_total
,payment_details
。created_on
,receipt_details
。id
,receipt_details
。receipt_no
,{{1} }。receipt_details
,site_id
。receipt_details
,vendor_id
。receipt_details
,work
。receipt_details
,description
。 receipt_details
,date
。receipt_details
,amount
。receipt_details
,tax_type
。receipt_details
,tax
。{{ 1}},receipt_details
。subtotal
,receipt_details
。grand_total
,receipt_details
。created_on
,vendor
。{{1} },id
。vendor
LEFT JOIN vname
ON site
。id
= site
。sname
或vendor
。vendor
= id
。payment_details
LEFT JOIN vendor_id
ON vendor
。id
= receipt_details
。vendor_id
或site
。site
= id
。payment_details
WHERE site_id
。site
&gt; ='2018-05-01'和{{1} }。id
&lt; ='2018-05-31'和receipt_details
。site_id
&gt; ='2018-05-01'和payment_details
。{{1} }&lt; ='2018-05-31'
文件名:D:/xampp/htdocs/construct/system/database/DB_driver.php
行号:691 提前谢谢......
答案 0 :(得分:0)
希望这会对您有所帮助:(未经测试)
您的查询结构应该是这样的,只需提示您做必要的更改
$sql = 'SELECT payment_details.id,payment_details.payment_no,payment_details.site_id,payment_details.vendor_id,payment_details.work,payment_details.description,payment_details.date,payment_details.amount,payment_details.tax_type,payment_details.tax,payment_details.subtotal,payment_details.grand_total,payment_details.created_on,receipt_details.id,receipt_details.receipt_no,receipt_details.site_id,receipt_details.vendor_id,receipt_details.work,receipt_details.description,receipt_details.date,receipt_details.amount,receipt_details.tax_type,receipt_details.tax,receipt_details.subtotal,receipt_details.grand_total,receipt_details.created_on,vendor.id,vendor.vname,site.id,site.sname
FROM payment_details
JOIN (vendor, receipt_details, site)
ON (vendor.id=payment_details.vendor_id OR vendor.id=receipt_details.vendor_id
AND site.id=payment_details.site_id OR site.id=receipt_details.site_id)';
$query = $this->db->query($sql);
return $query->result();