Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Como crear subconsulta SQL en Laravel

Hola tengo la siguiente consulta en SQL quisiera llevarla a Laravel pero no tengo ni la menor idea al respecto, mi consulta en SQL es la siguiente:

SELECT SUBQUERY.*,SUM(SUBQUERY.TOTAL) AS IMPORTE,(SUBQUERY.amount+SUBQUERY.tip) AS    IMPORT_PROPINA
FROM (
SELECT notas.*, posee.qty, productos.shopping_price,(productos.shopping_price * posee.qty) AS TOTAL
FROM posee
JOIN productos ON productos.id = posee.id_producto 
JOIN notas ON notas.id = posee.id_nota
)
AS SUBQUERY
GROUP BY SUBQUERY.id

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$result = DB::select("SELECT SUBQUERY.*,SUM(SUBQUERY.TOTAL) AS IMPORTE,(SUBQUERY.amount+SUBQUERY.tip) AS    IMPORT_PROPINA FROM ( SELECT notas.*, posee.qty, productos.shopping_price, productos.shopping_price * posee.qty) AS TOTAL FROM posee
JOIN productos ON productos.id = posee.id_producto JOIN notas ON notas.id = posee.id_nota)
AS SUBQUERY
GROUP BY")

You only need to wrap your queries with DB::select().

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading