Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
WITH Q1 AS (     SELECT          MT.Id AS MasterTest_Id,         SUM(PT.NumberOfTest) AS NumberOfTest_Q1     FROM Contracts_NotEntered CNE     LEFT JOIN Parts P ON P.Contract_Id = CNE.Contract_Id     LEFT JOIN PartTests PT ON PT.Part_Id = P.Id     LEFT JOIN MasterTests MT ON MT.Id = PT.MasterTest_Id     WHERE CNE.Contract_Id = 28053        AND P.Status = 1        AND PT.Status = 1         AND MT.Status = 1     GROUP BY MT.Id ), Q2 AS (     SELECT          PT.MasterTest_Id,         SUM(PT.NumberOfTest) AS NumberOfTest_Q2     FROM Contracts_NotEntered CNE     LEFT JOIN Parts P ON CNE.Part_Id = P.Id     LEFT JOIN PartTests PT ON PT.Part_Id = P.Id     WHERE CNE.Contract_Id = 28053        AND P.Status = 1        AND PT.Status = 1     GROUP BY PT.MasterTest_Id ), Q3 AS (     SELECT          PT.MasterTest_Id,         SUM(PT.NumberOfTest) AS NumberOfTest_Q3     FROM Contracts_IsEnteredExit CIE     LEFT JOIN Parts P ON CIE.Part_Id = P.Id     LEFT JOIN PartTests PT ON PT.Part_Id = P.Id     WHERE CIE.Contract_Id = 28053        AND P.Status = 1        AND PT.Status = 1     GROUP BY PT.MasterTest_Id ) SELECT MasterTests.Name,     COALESCE(Q1.MasterTest_Id, Q2.MasterTest_Id) AS MasterTest_Id,     Q1.NumberOfTest_Q1 As TotalNumberOfTest,     Q2.NumberOfTest_Q2 As NotEnteredNumberOfTest, isnull(Q3.NumberOfTest_Q3,0) As EnterExtNumberOfTest FROM Q1 FULL JOIN Q2 ON Q1.MasterTest_Id = Q2.MasterTest_Id FULL JOIN Q3 ON Q1.MasterTest_Id = Q3.MasterTest_Id Left Join MasterTests On MasterTests.Id = q1.MasterTest_Id ORDER BY MasterTest_Id; ای

Stuck with a problem? Got Error? Ask AI support!

Copy Clear