Message: Return type of CI_Session_files_driver::open($save_path, $name) should either be compatible with SessionHandlerInterface::open(string $path, string $name): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Message: Return type of CI_Session_files_driver::close() should either be compatible with SessionHandlerInterface::close(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Message: Return type of CI_Session_files_driver::read($session_id) should either be compatible with SessionHandlerInterface::read(string $id): string|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Message: Return type of CI_Session_files_driver::write($session_id, $session_data) should either be compatible with SessionHandlerInterface::write(string $id, string $data): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Message: Return type of CI_Session_files_driver::destroy($session_id) should either be compatible with SessionHandlerInterface::destroy(string $id): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Message: Return type of CI_Session_files_driver::gc($maxlifetime) should either be compatible with SessionHandlerInterface::gc(int $max_lifetime): int|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
MySql pobieranie danych pogrupowanych według godziny
Znacznik czasu często stosujemy w bazach danych aby zaznaczyć datę i godzinę utworzenia wpisu jednak często do statystyk potrzebujemy danych z określonych przedziałów czasowych jak na przykład liczbę wyników pogrupowanych według godziny.
Skorzystamy z przykładowej tabeli o nazwie "orders" do której dodajemy kolejno wiersze zapisując dokładną datę w kolumnie "time":
id
value
time
11243
120.89
2020-05-14 22:12:49
11263
210.68
2020-05-14 22:18:32
11243
60.78
2020-05-14 22:45:12
11250
132.10
2020-05-14 23:10:36
Więc teraz chcemy pobrać ilość zamówień dodanych w określonej godzinie w tym celu skorzystamy z funkcji DATE_FORMAT() podając jako argument %H co oznacza godzinę z zakresu 00-23
Całe zapytanie wygląda następująco:
SELECT COUNT(id) AS orders, DATE_FORMAT(time,\'%H\') AS hour FROM orders WHERE time= 2020-05-14 GROUP BY hour
Wykonując to zapytanie na fragmencie powyższej tabeli otrzymamy następujący wynik
orders
hour
22
3
23
1
Jak widać tak prostym zapytaniem można otrzymać całkiem ciekawe przedstawienie danych bardzo przydatne w różnego rodzaju statystykach.