Begrü,
ich habe in Problem mit nachfolgendem Statement. Unter MySql 5x funktioniert es, aber unter 4.0 nicht. Ich kann nicht ganz glauben, dass diese subselect nicht möglich ist. Doku über 4.0 habe ich leider keine gefunden, nur 4.1 und da ist es definietiv beschrieben, dass es funktionieren muss.. über einen Rat, wie ich das statement zum laufen bringe, wäre ich also sehr dankbar
select sum(`total`)as 's_total', sum(`day`) as 's_day', sum(`week`) as 's_week', sum(`month`) as 's_month', sum(`year`) as 's_year' from (
SELECT sum( `count` ) AS 'total', 0 AS 'day', 0 AS 'week', 0 AS 'month', 0 AS 'year', 0 AS `groupby`
FROM `dbcounter_count`
GROUP BY `groupby`
UNION SELECT 0 AS 'total', sum( `count` ) AS 'day', 0 AS 'week', 0 AS 'month', 0 AS 'year', DATE_FORMAT( FROM_UNIXTIME( `first_access` ) , '%Y%m%d' ) AS 'groupby'
FROM `dbcounter_count`
WHERE DATE_FORMAT( FROM_UNIXTIME( `first_access` ) , '%Y%m%d' ) = DATE_FORMAT( NOW( ) , '%Y%m%d' )
GROUP BY `groupby`
UNION SELECT 0 AS 'total', 0 AS 'day', sum( `count` ) AS 'week', 0 AS 'month', 0 AS 'year', DATE_FORMAT( FROM_UNIXTIME( `first_access` ) , '%v %Y' ) AS 'groupby'
FROM `dbcounter_count`
WHERE DATE_FORMAT( FROM_UNIXTIME( `first_access` ) , '%v %Y' ) = DATE_FORMAT( NOW( ) , '%v %Y' )
GROUP BY `groupby`
UNION SELECT 0 AS 'total', 0 AS 'day', 0 AS 'week', sum( `count` ) AS 'month', 0 'year', DATE_FORMAT( FROM_UNIXTIME( `first_access` ) , '%m %Y' ) AS 'groupby'
FROM `dbcounter_count`
WHERE DATE_FORMAT( FROM_UNIXTIME( `first_access` ) , '%m %Y' ) = DATE_FORMAT( NOW( ) , '%m %Y' )
GROUP BY `groupby`
UNION SELECT 0 AS 'total', 0 AS 'day', 0 AS 'week', 0 AS 'month', sum( `count` ) AS 'year', YEAR( FROM_UNIXTIME( `first_access` ) ) AS 'groupby'
FROM `dbcounter_count`
WHERE YEAR( FROM_UNIXTIME( `first_access` ) ) = DATE_FORMAT( NOW( ) , '%Y' )
GROUP BY `groupby`
) AS 'iv'
Danke,
ChP
ich habe in Problem mit nachfolgendem Statement. Unter MySql 5x funktioniert es, aber unter 4.0 nicht. Ich kann nicht ganz glauben, dass diese subselect nicht möglich ist. Doku über 4.0 habe ich leider keine gefunden, nur 4.1 und da ist es definietiv beschrieben, dass es funktionieren muss.. über einen Rat, wie ich das statement zum laufen bringe, wäre ich also sehr dankbar
select sum(`total`)as 's_total', sum(`day`) as 's_day', sum(`week`) as 's_week', sum(`month`) as 's_month', sum(`year`) as 's_year' from (
SELECT sum( `count` ) AS 'total', 0 AS 'day', 0 AS 'week', 0 AS 'month', 0 AS 'year', 0 AS `groupby`
FROM `dbcounter_count`
GROUP BY `groupby`
UNION SELECT 0 AS 'total', sum( `count` ) AS 'day', 0 AS 'week', 0 AS 'month', 0 AS 'year', DATE_FORMAT( FROM_UNIXTIME( `first_access` ) , '%Y%m%d' ) AS 'groupby'
FROM `dbcounter_count`
WHERE DATE_FORMAT( FROM_UNIXTIME( `first_access` ) , '%Y%m%d' ) = DATE_FORMAT( NOW( ) , '%Y%m%d' )
GROUP BY `groupby`
UNION SELECT 0 AS 'total', 0 AS 'day', sum( `count` ) AS 'week', 0 AS 'month', 0 AS 'year', DATE_FORMAT( FROM_UNIXTIME( `first_access` ) , '%v %Y' ) AS 'groupby'
FROM `dbcounter_count`
WHERE DATE_FORMAT( FROM_UNIXTIME( `first_access` ) , '%v %Y' ) = DATE_FORMAT( NOW( ) , '%v %Y' )
GROUP BY `groupby`
UNION SELECT 0 AS 'total', 0 AS 'day', 0 AS 'week', sum( `count` ) AS 'month', 0 'year', DATE_FORMAT( FROM_UNIXTIME( `first_access` ) , '%m %Y' ) AS 'groupby'
FROM `dbcounter_count`
WHERE DATE_FORMAT( FROM_UNIXTIME( `first_access` ) , '%m %Y' ) = DATE_FORMAT( NOW( ) , '%m %Y' )
GROUP BY `groupby`
UNION SELECT 0 AS 'total', 0 AS 'day', 0 AS 'week', 0 AS 'month', sum( `count` ) AS 'year', YEAR( FROM_UNIXTIME( `first_access` ) ) AS 'groupby'
FROM `dbcounter_count`
WHERE YEAR( FROM_UNIXTIME( `first_access` ) ) = DATE_FORMAT( NOW( ) , '%Y' )
GROUP BY `groupby`
) AS 'iv'
Danke,
ChP
Kommentar