douluhaikao93943 2019-07-17 11:39
浏览 76

选择“从数据库获取数据”查询

I have two tables joined called user and records with the structure below. With query below, i am trying to get users with status = 1 who have hours or seconds > 0. When i run the query, it gives me user 142 who has status 0.

The query actually returns the two rows in the user table. It should return just one row.. i.e user 199

What is wrong with my query please ?

user

id    status
199    1
142    0

records

user_id  hours  seconds
  199    10      90
  144     0      800

Controller

$results = array();
$results = $this->db->query("SELECT user.id, user.status, records.hours, records.seconds 
                             from user 
                             INNER JOIN records 
                                 ON user.id = records.user_id 
                             WHERE user.status = 1 
                               and records.hours 
                                or records.seconds > 0  ");
$get_results = $results->result_array();
return $get_results;
  • 写回答

1条回答 默认 最新

  • douguai4653 2019-07-17 11:42
    关注

    user brackets in between OR condition

    $results = array();
    $results = $this->db->query("SELECT user.id,user.status,records.hours,records.seconds 
                                 FROM user 
                                 INNER JOIN records 
                                     ON user.id = records.user_id 
                                 WHERE user.status = 1 
                                   AND (records.hours > 0 OR records.seconds > 0)");
    $get_results = $results->result_array();
    return $get_results;
    
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大