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
CREATE TABLE test ( numlot varchar(10), verouille varchar(10), code int ); Insert test(numlot,verouille, code) values('LOT1', 'O', 1); Insert test(numlot,verouille, code) values('LOT1', 'N', 2); Insert test(numlot,verouille, code) values('LOT2', 'O', 3); Insert test(numlot,verouille, code) values('LOT2', 'O', 4); Insert test(numlot,verouille, code) values('LOT3', 'N', 5); Insert test(numlot,verouille, code) values('LOT3', 'N', 6); CREATE TABLE testlot ( numlot varchar(10) ); Insert testlot(numlot) values('LOT1'); Insert testlot(numlot) values('LOT2'); Insert testlot(numlot) values('LOT3'); Insert testlot(numlot) values('LOT4'); select tl.numlot, SUM(CASE t.verouille WHEN 'O' THEN 1 WHEN 'N' THEN 0 ELSE 0 END) as test, count(*) as test2 from testlot tl left outer join test t on t.numlot = tl.numlot Group by tl.numlot

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

Copy Clear