sql >> Database >  >> RDS >> Mysql

Hoe onbewerkte query's uitvoeren met Laravel 5.1?

Ik vond de oplossing in dit onderwerp en ik codeer dit:

$cards = DB::select("SELECT
        cards.id_card,
        cards.hash_card,
        cards.`table`,
        users.name,
        0 as total,
        cards.card_status,
        cards.created_at as last_update
    FROM cards
    LEFT JOIN users
    ON users.id_user = cards.id_user
    WHERE hash_card NOT IN ( SELECT orders.hash_card FROM orders )
    UNION
    SELECT
        cards.id_card,
        orders.hash_card,
        cards.`table`,
        users.name,
        sum(orders.quantity*orders.product_price) as total, 
        cards.card_status, 
        max(orders.created_at) last_update 
    FROM menu.orders
    LEFT JOIN cards
    ON cards.hash_card = orders.hash_card
    LEFT JOIN users
    ON users.id_user = cards.id_user
    GROUP BY hash_card
    ORDER BY id_card ASC");


  1. Oracle Database 12c-software installeren op Windows

  2. Recursielimiet overschreden in niet-recursieprocedure

  3. hoe sqlite te synchroniseren met Mysql

  4. Hoe TimescaleDB gemakkelijk te implementeren?