Par chyb s phpmyadmina
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '--prva tabulka na vitazstva doma
FROM (
SELECT c.id,c.name, COUNT(name) ' at line 5
za -- se dava mezera
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as b
)
GROUP BY team_id,nazov
LIMIT 0, 25
tabulka se aliasuje bez AS, coz je trochu zmatene, ze sloupce to zas mit musi, ale co uz. Navic, pro union nemusis davat tabulkam aliasy., takze ani a ani b tam byt nemusi
SELECT team_id,nazov,SUM(body_doma) + SUM(body_vonku) as body
FROM
(
(
SELECT id as team_id,name as nazov, body_doma , 0 as body_vonku -- prva tabulka na vitazstva doma
FROM
(
SELECT c.id_club as id,c.name, COUNT(name) * 3 as body_doma
FROM kent_club c
JOIN kent_result r ON r.id_home = c.id_club
WHERE r.goal_home > r.goal_away
GROUP BY c.id_club
) as vit_doma
)
UNION ALL
(
SELECT id as team_id, team_name as nazov, 0 as body_doma, body_vonku
FROM
(
SELECT c.id_club as id,c.name as team_name, COUNT(name) * 3 as body_vonku
FROM kent_club c
JOIN kent_result r ON r.id_away = c.id_club
WHERE goal_home < goal_away
GROUP BY c.id_club
) as vit_vonku
)
) as x
GROUP BY team_id,nazov
-- bys mohl taky poslat sql prikazy pro vytvoreni tabulek... Pac bez tabulek se neda sql dotaz spustit v phpmyadmin
CREATE TABLE IF NOT EXISTS `kent_league` (
`id_league` int(11) NOT NULL AUTO_INCREMENT,
`name` text COLLATE utf8_czech_ci DEFAULT NULL,
PRIMARY KEY (`id_league`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;
CREATE TABLE IF NOT EXISTS `kent_result` (
`id_result` int(11) NOT NULL AUTO_INCREMENT,
`id_league` int(11) DEFAULT NULL,
`id_home` int(11) DEFAULT NULL,
`id_away` int(11) DEFAULT NULL,
`goal_home` int(11) DEFAULT NULL,
`goal_away` int(11) DEFAULT NULL,
PRIMARY KEY (`id_result`),
KEY `id_league` (`id_league`),
KEY `id_home` (`id_home`),
KEY `id_away` (`id_away`),
KEY `goal_home` (`goal_home`),
KEY `goal_away` (`goal_away`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;
CREATE TABLE IF NOT EXISTS `kent_club` (
`id_club` int(11) NOT NULL AUTO_INCREMENT,
`id_league` int(11) DEFAULT NULL,
`name` text COLLATE utf8_czech_ci DEFAULT NULL,
`manager` text COLLATE utf8_czech_ci DEFAULT NULL,
`state` text COLLATE utf8_czech_ci DEFAULT NULL,
PRIMARY KEY (`id_club`),
KEY `id_league` (`id_league`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;