用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2731|回复: 3
收起左侧

[讨论/交流] 关于sql查询的语句

[复制链接]
发表于 2013-4-11 13:08:47 | 显示全部楼层 |阅读模式
是想执行这样语句sql
$sql = select count(*) from goods_stock_info where goods_id = 13 and goods_intact_num > 0 or goods_return_num >0 or goods_damage_num >0;

用CI里面的方法对应写

$this->db->select("*");
$this->db->from("goods_stock_info");
$this->db->or_where(array('goods_intact_num > '=>0,'goods_return_num >'=>0,'goods_damage_num >'=>0));
$this->db->where('goods_id',$goods_id);
$query = $this->db->count_all_results();

难道这样不对?反正执行的结果是不对。

发表于 2013-4-11 15:35:20 | 显示全部楼层
echo $this->db->last_query();看下不就都清楚了
发表于 2013-4-11 19:33:46 | 显示全部楼层
这么复杂的语句 直接用 query 吧,别用 AR 了
 楼主| 发表于 2013-4-12 14:12:30 | 显示全部楼层
Hex 发表于 2013-4-11 19:33
这么复杂的语句 直接用 query 吧,别用 AR 了

嗯 还真最后就是用query写的。

本版积分规则