在Ignited Datatable中没有条件和嵌套查询

时间:2018-02-11 18:29:42

标签: php sql codeigniter

我正在使用Ignited Datatables进行codeigniter 在我的控制器中我有类似的东西:

     $this->datatables
    ->select("customer, sale_status, return_id")
    ->join('warehouses', 'warehouses.id=sales.warehouse_id', 'left')
    ->from('sales')
    ->where('warehouse_id', $warehouse_id);          

退出罚款。但现在有以下查询运行

    "SELECT * from sales where now() > return_date and id NOT IN (SELECT 
    sale_Id FROM sales where sale_id IS NOT NULL)"

我不知道怎么用点燃的方式说出来,因为我没有在他们的文档中找到任何“WHERE NOT IN”和嵌套的原始查询语法。任何帮助将不胜感激,我很抱歉我的英语不好。

2 个答案:

答案 0 :(得分:3)

codeigniter中的正确方法是

$strSubQuery = $this->db->select('sale_Id')->from('sales')->where('sale_id IS NOT NULL', NULL, false)->get_compiled_select();

echo $this->db
        ->select('*')
        ->from('sales')
        ->where('return_date <= ', 'now()', false)
        ->where_not_in('id', $strSubQuery, false)
        ->get_compiled_select();

基本上这意味着您需要向where_not_in图书馆添加Ignited Datatables功能

我不知道你是怎么做到的,但一个例子可能是

public function where_not_in($key_condition, $val = NULL, $blnEscape = true)
{
    $this->ci->db->where_in($key_condition, $val, $blnEscape);
    return $this;
}

答案 1 :(得分:0)

来自文件:

library(tidyverse)

h_label_missing <- h %>% 
  filter(map_lgl(label, ~all(is.na(.)))) %>% 
  select(-label)

h %>% 
  filter(!map_lgl(label, ~all(is.na(.)))) %>% 
  mutate(label = map(label, bind_rows)) %>% 
  unnest() %>% 
  full_join(h_label_missing, by = "mainId")

# A tibble: 6 x 6
#     mainId         id url                                                                                  name             color  default
#       <chr>     <int> <chr>                                                                                <chr>            <chr>  <lgl>  
# 1 216226960 431676528 https://api.github.com/repos/emergenzeHack/terremotocentro/labels/per%20sviluppatori per sviluppatori d4c5f9 F      
# 2 216226960 442034204 https://api.github.com/repos/emergenzeHack/terremotocentro/labels/sito%20principale  sito principale  5319e7 F      
# 3 215647494 442051239 https://api.github.com/repos/emergenzeHack/terremotocentro/labels/mappa              mappa            0052cc F      
# 4 215647494 431676528 https://api.github.com/repos/emergenzeHack/terremotocentro/labels/per%20sviluppatori per sviluppatori d4c5f9 F      
# 5 215647494 442034204 https://api.github.com/repos/emergenzeHack/terremotocentro/labels/sito%20principale  sito principale  5319e7 F      
# 6 242390063        NA NA                                                                                   NA               NA     NA     
  

生成WHERE字段NOT IN('item','item')SQL查询加入   如果合适的话

请参阅here

所以在你的情况下,你可以试试这个:

$this->db->where_not_in()