交错两个不同SQL表的行,按行分组

时间:2016-10-04 12:38:38

标签: codeigniter

我的Sql查询是这样的

$view =  mysql_query ("SELECT domain,count(distinct session_id) as 
         views FROM `statistik` left join statistik_strippeddomains on 
         statistik_strippeddomains.id = statistik.strippeddomain WHERE
         `angebote_id` = '".(int)$_GET['id']."' and strippeddomain!=1 
         group by domain having count (distinct session_id) >
         ".(int)($film_daten['angebote_views']/100)."  order 
         count(distinct session_id$vladd) desc limit 25");

我如何编写其Codeigniter模型我感谢任何帮助

1 个答案:

答案 0 :(得分:1)

试试这个

$this->db->select('statistik.domain,statistik.count(DISTINCT(session_id)) as views');
$this->db->from('statistik');
$this->db->join('statistik_strippeddomains', 'statistik_strippeddomains.id = statistik.strippeddomain', 'left'); 
$this->db->where('angebote_id',$_GET['id']);
$this->db->where('strippeddomain !=',1);
$this->db->group_by('domain');
$this->db->having('count > '.$film_daten['angebote_views']/100, NULL, FALSE);
$this->db->order_by('count','desc');
$this->db->limit('25');
$query = $this->db->get();

评论我如果您有任何疑问。