syntax :
------------
select c.castid,
sum(CASE WHEN strandid = 1 AND s.castend - s.caststart >0 THEN 1 ELSE 0 END) as S1,
sum(CASE WHEN strandid = 2 AND s.castend - s.caststart >0 THEN 1 ELSE 0 END) as S2,
sum(CASE WHEN strandid = 3 AND s.castend - s.caststart >0 THEN 1 ELSE 0 END) as S3,
sum(CASE WHEN strandid = 4 AND s.castend - s.caststart >0 THEN 1 ELSE 0 END) as S4,
sum(CASE WHEN strandid = 5 AND s.castend - s.caststart >0 THEN 1 ELSE 0 END) as S5,
sum(CASE WHEN strandid = 6 AND s.castend - s.caststart >0 THEN 1 ELSE 0 END) as S6
from tbcast c JOIN tbstrand s ON c.castid = s.castid
group by c.castid