如何在Laravel中编写查询语句?

时间:2018-01-14 17:47:19

标签: sql laravel

任何人都可以指导我在laravel中编写sql语句。

这里是我的原始sql语句

SELECT H.pos_sales_code,
       customer.customer_group,
       H.customer_id,
       customer.NAME          AS customer,
       customer.phone,
       customer.email,
       customer.referral_type AS referral,
       H.created_at           AS first_visit,
       pos_sales_product.product_name
FROM   pos_sales H
       INNER JOIN (SELECT customer_id,
                          Min(created_at) AS first_visit
                   FROM   pos_sales
                   GROUP  BY customer_id) X
               ON H.customer_id = X.customer_id
                  AND H.created_at = X.first_visit
       LEFT JOIN customer
              ON customer.id = H.customer_id
       LEFT JOIN pos_sales_product
              ON H.pos_sales_code = pos_sales_product.pos_sales_code 

如何在laravel中编写此查询。提前感谢所有人......

2 个答案:

答案 0 :(得分:0)

您是否尝试过使用文档的原始表达式? https://laravel.com/docs/5.5/queries#raw-expressions

答案 1 :(得分:0)

使用laravel查询构建器的查询应该具体:

UPDATE members
SET timeOnline = timeOnline + INTERVAL :time SECOND
WHERE memberID = :memberID