SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE Invoices (`Amount` int); INSERT INTO Invoices (`Amount`) VALUES (1012), (1055), (1055), (1200), (1265), (1270); CREATE TABLE Payments (`Amount` int); INSERT INTO Payments (`Amount`) VALUES (1055), (1200), (1265), (99); SELECT * FROM Invoices; SELECT * FROM Payments; SELECT Invoices.amount, COUNT(Invoices.amount) AS invoices_count, ( SELECT COUNT(Payments.amount) FROM Payments WHERE Invoices.amount=Payments.amount ) AS payments_count FROM Invoices GROUP BY Invoices.amount UNION SELECT Payments.amount, 0 AS invoices_count, ( SELECT COUNT(Invoices.amount) FROM Invoices WHERE Invoices.amount=Payments.amount ) AS payments_count FROM Payments GROUP BY Payments.amount
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear