我正在尝试在Laravel Nova Lens上运行原始SQL查询。 你能帮我做吗?
我确实尝试将sql转换为雄辩的查询生成器。 但是,它的代码很长。 另外[Orator] [1]不再起作用。
如果有人可以成为我的Laravel nova在线教师,我将不胜感激。
这是缩短的SQL查询:
DECLARE @from_month INT;
DECLARE @to_month INT;
DECLARE @month_range INT;
DECLARE @year_monitor INT;
DECLARE @text_match_on_item_name VARCHAR(50);
DECLARE @Customer_id VARCHAR(50) ;
DECLARE @doc_type VARCHAR(50) ;
SET @from_month =10;
SET @to_month = 12;
SET @month_range = 4;
SET @year_monitor = 2018;
SET @text_match_on_item_name = '%';
SET @Customer_id ='%'; -- in order to select all id's enter '%'
SET @doc_type = '%מס%';
SELECT
i.item_num AS ItemNum,
i.item_name AS ItemName,
i.itm_qnt AS Stock,
sum(d.itm_qnt_out-d.itm_qnt_in) AS QTOUT,
CASE WHEN i.itm_qnt>0 THEN
sum(CASE WHEN DatePart(mm,[invdate]) BETWEEN @from_month AND @to_month THEN d.itm_qnt_out-d.itm_qnt_in ELSE 0 END ) -i.itm_qnt
ELSE
sum(CASE WHEN DatePart(mm,[invdate]) BETWEEN @from_month AND @to_month THEN d.itm_qnt_out-d.itm_qnt_in ELSE 0 END )
END
AS [PERIODICAL OEDER],
/* IF stock>0 THEN yearly_order = YearlySales-Stock ELSE yearly_order = YearlySales */
CASE WHEN i.itm_qnt>0 THEN
sum(d.itm_qnt_out-d.itm_qnt_in)-i.itm_qnt
ELSE
sum(d.itm_qnt_out-d.itm_qnt_in)
END
AS [YEARLY OEDER],
sum(CASE WHEN DatePart(mm,[invdate]) = '12' THEN d.itm_qnt_out-d.itm_qnt_in ELSE 0 END) AS December
/*Repeat for every month*/
FROM
turtle.dbo.t_items AS i
FULL OUTER JOIN
turtle.dbo.t_items_dtl AS d ON i.item_num = d.item_num
WHERE DatePart(YEAR, [invdate]) = @year_monitor and d.asmachta like @doc_type
and i.item_name like '%'+@text_match_on_item_name+'%' and cust_id like @Customer_id and
i.item_num not in (0, 3318,3310,3319,3309,3638,3052) -- מוצרים להשכרה שלא צריכים להופיע
GROUP BY
i.item_num, i.item_name, i.itm_qnt
order by
[PERIODICAL OEDER] desc