Присоединиться к столу на laravel - PullRequest
0 голосов
/ 17 марта 2020
SELECT title AS quiz_namenik, fullname AS profile_name, nik, store_code, 
siebel_name AS store_name, MONTHNAME(start_date) AS `month`, score, 
start_date, end_date,profil.created_at AS account_created_date, 
profil.updated_at AS account_last_update
FROM
(
    SELECT users.id, fullname, nik, siebel_name,store_code,  
    users.created_at, users.updated_at  
    FROM users
    INNER JOIN stores ON users.store_id = stores.id
) AS profil,
(
    SELECT kepo_quizs.id, score.user_id, title, score, start_date, end_date 
    FROM kepo_quizs
    LEFT JOIN kepo_user_score AS score ON score.quiz_id = kepo_quizs.id
    WHERE `activity_category_id` = '2'
) AS quiz    
WHERE quiz.user_id = profil.id 
AND (`start_date` >= '2019-01-01' AND `end_date` <= '2019-12-31')
ORDER BY title ASC, fullname ASC

Это мой запрос, который я хочу изменить на laravel присоединений, можете помочь мне, пожалуйста

enter image description here

1 Ответ

0 голосов
/ 17 марта 2020

Вы можете использовать следующий код

DB::SELECT("SELECT title AS quiz_namenik, fullname AS profile_name, nik, store_code, 
    siebel_name AS store_name, MONTHNAME(start_date) AS `month`, score, 
    start_date, end_date,profil.created_at AS account_created_date, 
    profil.updated_at AS account_last_update
    FROM
    (
        SELECT users.id, fullname, nik, siebel_name,store_code,  
        users.created_at, users.updated_at  
        FROM users
        INNER JOIN stores ON users.store_id = stores.id
    ) AS profil,
    (
        SELECT kepo_quizs.id, score.user_id, title, score, start_date, end_date 
        FROM kepo_quizs
        LEFT JOIN kepo_user_score AS score ON score.quiz_id = kepo_quizs.id
        WHERE `activity_category_id` = '2'
    ) AS quiz    
    WHERE quiz.user_id = profil.id 
    AND (`start_date` >= '2019-01-01' AND `end_date` <= '2019-12-31')
    ORDER BY title ASC, fullname ASC");
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...