MySQL execute query only if a statement is verified -
i have query working well:
select disciplina, categoria, if (max(`london 2012`) > 0, 'yes', 'no') 'london 2012', if (max(`beijing 2008`) > 0, 'yes', 'no') 'beijing 2008', if (max(`athens 2004`) > 0, 'yes', 'no') 'athens 2004', if (max(`sydney 2000`) > 0, 'yes', 'no') 'sydney 2000', if (max(`atlanta 1996`) > 0, 'yes', 'no') 'atlanta 1996', if (max(`barcelona 1992`) > 0, 'yes', 'no') 'barcelona 1992', if (max(`seoul 1988`) > 0, 'yes', 'no') 'seoul 1988', if (max(`los angeles 1984`) > 0, 'yes', 'no') 'los angeles 1984', if (max(`moscow 1980`) > 0, 'yes', 'no') 'moscow 1980', if (max(`montreal 1976`) > 0, 'yes', 'no') 'montreal 1976', if (max(`munich 1972`) > 0, 'yes', 'no') 'munich 1972', if (max(`mexico 1968`) > 0, 'yes', 'no') 'mexico 1968', if (max(`tokyo 1964`) > 0, 'yes', 'no') 'tokyo 1964', if (max(`rome 1960`) > 0, 'yes', 'no') 'rome 1960', if (max(`melbourne / stockholm 1956`) > 0, 'yes', 'no') 'melbourne / stockholm 1956', if (max(`helsinki 1952`) > 0, 'yes', 'no') 'helsinki 1952', if (max(`london 1948`) > 0, 'yes', 'no') 'london 1948', if (max(`berlin 1936`) > 0, 'yes', 'no') 'berlin 1936', if (max(`los angeles 1932`) > 0, 'yes', 'no') 'los angeles 1932', if (max(`amsterdam 1928`) > 0, 'yes', 'no') 'amsterdam 1928', if (max(`paris 1924`) > 0, 'yes', 'no') 'paris 1924', if (max(`antwerp 1920`) > 0, 'yes', 'no') 'antwerp 1920', if (max(`stockholm 1912`) > 0, 'yes', 'no') 'stockholm 1912', if (max(`london 1908`) > 0, 'yes', 'no') 'london 1908', if (max(`st louis 1904`) > 0, 'yes', 'no') 'st louis 1904', if (max(`paris 1900`) > 0, 'yes', 'no') 'paris 1900', if (max(`athens 1896`) > 0, 'yes', 'no') 'athens 1896' ( select disciplina, categoria, if (olimpiade = 'london 2012', 1, 0) 'london 2012', if (olimpiade = 'beijing 2008', 1, 0) 'beijing 2008', if (olimpiade = 'athens 2004', 1, 0) 'athens 2004', if (olimpiade = 'sydney 2000', 1, 0) 'sydney 2000', if (olimpiade = 'atlanta 1996', 1, 0) 'atlanta 1996', if (olimpiade = 'barcelona 1992', 1, 0) 'barcelona 1992', if (olimpiade = 'seoul 1988', 1, 0) 'seoul 1988', if (olimpiade = 'los angeles 1984', 1, 0) 'los angeles 1984', if (olimpiade = 'moscow 1980', 1, 0) 'moscow 1980', if (olimpiade = 'montreal 1976', 1, 0) 'montreal 1976', if (olimpiade = 'munich 1972', 1, 0) 'munich 1972', if (olimpiade = 'mexico 1968', 1, 0) 'mexico 1968', if (olimpiade = 'tokyo 1964', 1, 0) 'tokyo 1964', if (olimpiade = 'rome 1960', 1, 0) 'rome 1960', if (olimpiade = 'melbourne / stockholm 1956', 1, 0) 'melbourne / stockholm 1956', if (olimpiade = 'helsinki 1952', 1, 0) 'helsinki 1952', if (olimpiade = 'london 1948', 1, 0) 'london 1948', if (olimpiade = 'berlin 1936', 1, 0) 'berlin 1936', if (olimpiade = 'los angeles 1932', 1, 0) 'los angeles 1932', if (olimpiade = 'amsterdam 1928', 1, 0) 'amsterdam 1928', if (olimpiade = 'paris 1924', 1, 0) 'paris 1924', if (olimpiade = 'antwerp 1920', 1, 0) 'antwerp 1920', if (olimpiade = 'stockholm 1912', 1, 0) 'stockholm 1912', if (olimpiade = 'london 1908', 1, 0) 'london 1908', if (olimpiade = 'st louis 1904', 1, 0) 'st louis 1904', if (olimpiade = 'paris 1900', 1, 0) 'paris 1900', if (olimpiade = 'athens 1896', 1, 0) 'athens 1896' summertotalmedals sport='athletics' ) games group disciplina, categoria order disciplina asc, categoria asc
i'd obtain single query, 2 types of queries.
1) first 1 obtain same information disciplina ='yes' @ london 2012
2) second 1 obtain same information disciplina = 'no' @ london 2012.
could this? tried myself poor results.
i'm not saying database design... ;)
why don't add filter in inner query this:
1) first 1 obtain same information disciplina ='yes' @ london 2012
select disciplina, categoria, if (max(`london 2012`) > 0, 'yes', 'no') 'london 2012', if (max(`beijing 2008`) > 0, 'yes', 'no') 'beijing 2008', if (max(`athens 2004`) > 0, 'yes', 'no') 'athens 2004', if (max(`sydney 2000`) > 0, 'yes', 'no') 'sydney 2000', if (max(`atlanta 1996`) > 0, 'yes', 'no') 'atlanta 1996', if (max(`barcelona 1992`) > 0, 'yes', 'no') 'barcelona 1992', if (max(`seoul 1988`) > 0, 'yes', 'no') 'seoul 1988', if (max(`los angeles 1984`) > 0, 'yes', 'no') 'los angeles 1984', if (max(`moscow 1980`) > 0, 'yes', 'no') 'moscow 1980', if (max(`montreal 1976`) > 0, 'yes', 'no') 'montreal 1976', if (max(`munich 1972`) > 0, 'yes', 'no') 'munich 1972', if (max(`mexico 1968`) > 0, 'yes', 'no') 'mexico 1968', if (max(`tokyo 1964`) > 0, 'yes', 'no') 'tokyo 1964', if (max(`rome 1960`) > 0, 'yes', 'no') 'rome 1960', if (max(`melbourne / stockholm 1956`) > 0, 'yes', 'no') 'melbourne / stockholm 1956', if (max(`helsinki 1952`) > 0, 'yes', 'no') 'helsinki 1952', if (max(`london 1948`) > 0, 'yes', 'no') 'london 1948', if (max(`berlin 1936`) > 0, 'yes', 'no') 'berlin 1936', if (max(`los angeles 1932`) > 0, 'yes', 'no') 'los angeles 1932', if (max(`amsterdam 1928`) > 0, 'yes', 'no') 'amsterdam 1928', if (max(`paris 1924`) > 0, 'yes', 'no') 'paris 1924', if (max(`antwerp 1920`) > 0, 'yes', 'no') 'antwerp 1920', if (max(`stockholm 1912`) > 0, 'yes', 'no') 'stockholm 1912', if (max(`london 1908`) > 0, 'yes', 'no') 'london 1908', if (max(`st louis 1904`) > 0, 'yes', 'no') 'st louis 1904', if (max(`paris 1900`) > 0, 'yes', 'no') 'paris 1900', if (max(`athens 1896`) > 0, 'yes', 'no') 'athens 1896' ( select disciplina, categoria, if (olimpiade = 'london 2012', 1, 0) 'london 2012', if (olimpiade = 'beijing 2008', 1, 0) 'beijing 2008', if (olimpiade = 'athens 2004', 1, 0) 'athens 2004', if (olimpiade = 'sydney 2000', 1, 0) 'sydney 2000', if (olimpiade = 'atlanta 1996', 1, 0) 'atlanta 1996', if (olimpiade = 'barcelona 1992', 1, 0) 'barcelona 1992', if (olimpiade = 'seoul 1988', 1, 0) 'seoul 1988', if (olimpiade = 'los angeles 1984', 1, 0) 'los angeles 1984', if (olimpiade = 'moscow 1980', 1, 0) 'moscow 1980', if (olimpiade = 'montreal 1976', 1, 0) 'montreal 1976', if (olimpiade = 'munich 1972', 1, 0) 'munich 1972', if (olimpiade = 'mexico 1968', 1, 0) 'mexico 1968', if (olimpiade = 'tokyo 1964', 1, 0) 'tokyo 1964', if (olimpiade = 'rome 1960', 1, 0) 'rome 1960', if (olimpiade = 'melbourne / stockholm 1956', 1, 0) 'melbourne / stockholm 1956', if (olimpiade = 'helsinki 1952', 1, 0) 'helsinki 1952', if (olimpiade = 'london 1948', 1, 0) 'london 1948', if (olimpiade = 'berlin 1936', 1, 0) 'berlin 1936', if (olimpiade = 'los angeles 1932', 1, 0) 'los angeles 1932', if (olimpiade = 'amsterdam 1928', 1, 0) 'amsterdam 1928', if (olimpiade = 'paris 1924', 1, 0) 'paris 1924', if (olimpiade = 'antwerp 1920', 1, 0) 'antwerp 1920', if (olimpiade = 'stockholm 1912', 1, 0) 'stockholm 1912', if (olimpiade = 'london 1908', 1, 0) 'london 1908', if (olimpiade = 'st louis 1904', 1, 0) 'st louis 1904', if (olimpiade = 'paris 1900', 1, 0) 'paris 1900', if (olimpiade = 'athens 1896', 1, 0) 'athens 1896' summertotalmedals sport='athletics' , olimpiade = 'london 2012' , disciplina='yes' ) games group disciplina, categoria order disciplina asc, categoria asc
the second, need change disciplina='no'. you're expecting of didn't understand question?
Comments
Post a Comment