将常规查询更改为Laravel查询生成器

时间:2016-10-15 04:51:46

标签: mysql laravel-5

如何使用Laravel查询构建器编写此常规查询?

SELECT `t1`.`id` , `i`.`item_description` AS `name` , SUM( t1.amount ) AS total, `u`.`name` AS `unit`
FROM `fees9_items` AS `t1`
LEFT JOIN `items` AS `i` ON `i`.`id` = `t1`.`item_id`
LEFT JOIN `mesure_units` AS `u` ON `u`.`id` = `i`.`unit`
LEFT JOIN `fees9` AS `f` ON `f`.`id` = `t1`.`fees9_id`
WHERE date >= '2016-01-01' AND (f.field1=1 OR f.field2=1 OR f.other =1)
GROUP BY `i`.`id` 

这部分很重要:

(f.field1=1 OR f.field2=1 OR f.other =1)

1 个答案:

答案 0 :(得分:1)

试一试,它应该有用

a = float(input())
if a > 0:
    y = a - 12
else:
    y = a
print(y)