URL: https://www.overclockers.at/coding-stuff/mysql_kopfweh_218311/page_1 - zur Vollversion wechseln!
ich versuche aus einer log datenbank (protokolliert werden zugriffe auf mehrere seiten in eine datenbank) die anzahl der benutzer pro tag jedoch im endeffekt summiert zu bekommen.
Code: PHPSELECT from_days(to_days(date)) AS Datum, COUNT(distinct ip) AS Besucher FROM db WHERE ( to_days( date ) - 1 ) < ( to_days( now( ) ) - 0) AND ( to_days( date ) ) > ( to_days( now( ) ) - 7) AND directory = "website1" GROUP BY Datum ORDER BY Datum DESC LIMIT 0, 300
Sollte passen, außer mysql hat da irgendwelche Eigenheiten.Code: PHPSELECT sum(Besucher) FROM (SELECT COUNT(distinct ip) AS Besucher FROM db WHERE ( to_days( date ) - 1 ) < ( to_days( now( ) ) - 0) AND ( to_days( date ) ) > ( to_days( now( ) ) - 7) AND directory = "website1" GROUP BY date)
Kleinigekit in der Fragestellung überlesen.
Jo klar. Aber so hat er die insgesamt eindeutigen User in dem Zeitraum. Er will aber, soweit ichs versteh, die Summe an pro Tag eindeutigen Usern haben. Sprich wenn ich die Seite heut und morgen ansurfe stehe ich zweimal in der Gesamtsumme. Bei deiner Variante einmal. (gesetz dem Fall ich beide male die selbe IP)
Sprich bei meiner Variante sind die Wiederbesucher auch dabei, und die will er glaub ich ja auch dabei haben.
// meh...
... leider geht das in mysql irgendwie nicht so recht mit verschachtelten abfragen - daher ja auch mein kopfweh ...
ZitatMySQL said: Documentation
#1248 - Every derived table must have its own alias
hm, dann probier mal
Code: PHPSELECT sum(v.Besucher) FROM (SELECT COUNT(distinct ip) AS Besucher FROM db WHERE ( to_days( date ) - 1 ) < ( to_days( now( ) ) - 0) AND ( to_days( date ) ) > ( to_days( now( ) ) - 7) AND directory = "website1" GROUP BY date) AS v
haha!!!
gelöst ist es - geht doch, nur muss man der temporären tabelle einen namen geben also demnach einfach:
Code: PHPSELECT sum(Besucher) FROM (SELECT COUNT(distinct ip) AS Besucher FROM db WHERE ( to_days( date ) - 1 ) < ( to_days( now( ) ) - 0) AND ( to_days( date ) ) > ( to_days( now( ) ) - 7) AND directory = "website1" GROUP BY date) AS temp_table
overclockers.at v4.thecommunity
© all rights reserved by overclockers.at 2000-2025