sql >> Database teknologi >  >> RDS >> Mysql

Hvordan tjekker man ind en anden tabel har ingen data, mens man laver mysql join?

Tilføj IF-betingelse i SQL-forespørgsel, noget som dette.

SELECT invoice_details.invoice_no,
       invoice_details.invoice_date,
       invoice_details.invoice_amount,
       SUM(IF(received_amount_details.received_amount IS NULL
               OR received_amount_details.received_amount = '', 0.0,
               received_amount_details.received_amount)) AS totalreceiptamt
FROM   (SELECT DISTINCT invoice_no,
                        received_amount
        FROM   received_amount_details) AS received_amount_details
       right join invoice_details
               ON received_amount_details.invoice_no =
                  invoice_details.invoice_no
WHERE  invoice_details.proje_id = '7'
GROUP  BY invoice_details.invoice_no 

Dette vil tilføje 0.0, da standardværdien ikke er receive_amount_details.received_amount ER NULL eller tom

Vi tilslutter os også for at få alle værdier fra siden invoice_details.

Du kan lære mere om IF-tilstand i MYSQL her,

https://www.w3schools.com/mysql/func_mysql_if.asp https://dev.mysql.com/doc/refman/8.0 /da/if.html




  1. MYSQL - få laveste bud fra tabelgruppe efter produkt (resultater mærkelige)

  2. Afkort alle tabeller i MySQL-databasen, der matcher et navnemønster

  3. MySQL-forespørgsel for at søge i et felt med JSON-streng

  4. Oracle.DataAccess.Client-afhængigheder