我需要在laravel Query中转换该查询

时间:2017-11-10 12:17:03

标签: mysql laravel

SELECT * 
  FROM `events` 
 WHERE (`customer_bookable` = 1 and template = 1 ) 
    OR (`customer_bookable` = 0 and template = 0 ) 
   and (`start_date_time` BETWEEN '2017-09-01 00:00:00' and '2017-09-21 00:00:00') 
   And (profile_id = 10) 
   and (event_live_status = 1) 
   and (class != 0) 
   and (privacy_status = 1)

2 个答案:

答案 0 :(得分:0)

你需要'或'部分的帮助吗?您可以使用在SQL中使用括号的闭包:

import re


txt = b'{"data":[{"categories":[{"id":"IAB3","label":"Business","parent":"IAB3","score":"0.223819028028717559","confident":true}],"url":"megatel.de"}]}'

pattern = r'"label":"(.*?)"'
labels = re.search(pattern, str(txt, 'utf-8')).groups()

print(labels[0])  # Business

答案 1 :(得分:0)

您的查询可能如下所示

$events = DB::('events')
    ->where( function ($query) {
         $query->where('customer_bookable',1)
               ->where('template',1)
               ->orWhere('customer_bookable',0)
               ->orWhere('template',0);
    })
    ->where( function ($query) {
          $query->whereBetween('start_date_time',['2017-09-01 00:00:00' and '2017-09-21 00:00:00'])
          ->where('profile_id',10)     
          ->where('event_live_status',1)
          ->where('class','!=',0)
          ->where('privacy_status',1);
     });