如何在Codeginter中使用SQL BETWEEN运算符在多个价格范围内选择数据

时间:2019-01-11 10:58:48

标签: php mysql codeigniter between

价格范围过滤器。

EX:>(0到10和15到20和60到100)

output$map <- renderLeaflet({

  from_to <- input$station

  df <- df.trip %>%
    filter(format(df.trip$starttime,"%Y-%m-%d") == input$date)

  if (from_to == "Start Station") {
    df <- df %>% 
      group_by(from_station_id) %>%
      summarize(n_trips = n()) %>% 
      left_join(df.station, by = c("from_station_id" = "station_id"))
  } else {
    df <- df %>% 
      group_by(to_station_id) %>%
      summarize(n_trips = n()) %>% 
      left_join(df.station, by = c("to_station_id" = "station_id"))
  }

  leaflet(df) %>%
    addTiles(group="OSM") %>%#OSM is default tile providor
    addProviderTiles(providers$CartoDB.Positron) %>%
    setView(
      lng=-122.335167,
      lat=47.608013,
      zoom=12
    )%>%
    addCircleMarkers(lng = ~long, lat = ~lat, weight = 1,
                     label=~name, radius = ~n_trips)
})

..... etc

2 个答案:

答案 0 :(得分:2)

我猜你在问组功能

$this->db->group_start();
  $this->db->where('sales >= ',  0);
  $this->db->where('sales <=',  10);
$this->db->group_end();
$this->db->or_group_start();
  $this->db->where('sales >=',  15);
  $this->db->where('sales <=',  20);
$this->db->group_end();

会产生

(`sales` >= 0 and `sales` <= 10) or (`sales` >= 15 and `sales` <= 20)

答案 1 :(得分:0)

在where条件下使用。

$this->db->where('(sales  >= 0 AND <= 10) OR (sales  >= 15 AND <= 20) OR (sales  >= 60 AND <= 100)',NULL, FALSE );