SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
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 ChatGPT!
Copy Clear