遭遇例1

MySQL用語集

カテゴリー: エラー  閲覧数:249 配信日:2017-08-17 09:14


エラー対応


修正前
public function Get1ExitpageRankingSession()
{

$query = "
 SELECT `user_id`, `visitor_session_id`,`title`, `request_url`, `http_referer`, `user_agent`, `screen_width`, `screen_height`, `access_datetime`,COUNT(*) AS `count` FROM `access` AS m
 WHERE `visitor_session_id` != '' AND NOT EXISTS (
     SELECT 1
     FROM `access` AS s
     WHERE m.`visitor_session_id` = s.`visitor_session_id`
     AND m.`access_datetime` < s.`access_datetime`
 
 AND m.`access_datetime`>=date(current_timestamp - interval 1 day)
 AND m.`access_datetime` < date(now())
 GROUP BY m.`request_url`
 ORDER BY `count` DESC
";
  return $this->executeFetchAll($query);
}


修正後
public function Get1ExitpageRankingSession()
{

$query = "
 SELECT ANY_VALUE(`user_id`) AS user_id, `visitor_session_id`,`title`, `request_url`, `http_referer`, `user_agent`, `screen_width`, `screen_height`, `access_datetime`,COUNT(*) AS `count` FROM `access` AS m
 WHERE `visitor_session_id` != '' AND NOT EXISTS (
     SELECT 1
     FROM `access` AS s
     WHERE m.`visitor_session_id` = s.`visitor_session_id`
     AND m.`access_datetime` < s.`access_datetime`
 
 AND m.`access_datetime`>=date(current_timestamp - interval 1 day)
 AND m.`access_datetime` < date(now())
 GROUP BY m.`request_url`
 ORDER BY `count` DESC
";
  return $this->executeFetchAll($query);
}



ANY_VALUE指定しても解決しない場合は?


一旦、ORDER BYをコメントアウトしてみる
・もしかすると不要な指定かも
※「ORDER BY」も、一意かどうかの判定に利用されるため注意が必要

指定期間人気ページランキング / 2020-5-28 → 2025-4-24
順位 ページタイトル抜粋 アクセス数
1 #1241 - オペランドに 1 個の列が必要です。 | エラー 3601
2 MySQL用語 1560
3 SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry | エラー 1356
4 クエリエラー: #1265 - 列 'カラム名' の 行 ★ でデータが切り捨てられました。 | エラー 1335
5 ( ! ) Fatal error: Uncaught PDOException: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value | エラー 927
6 Data truncated for column | エラー 608
7 where clause is ambiguous | エラー 600
8 Incorrect integer value | エラー 582
9 クエリエラー: #1294 - 列 'カラム名' に ON UPDATE旬は無効です。 | エラー 567
10 <> | 演算子 477
11 スキーマ | データベースの構造 451
12 インデックス | 最適化 407
13 #1067 - Invalid default value for 'id' | エラー 389
14 SELECT list is not in GROUP BY clause and contains nonaggregated column | エラー 265
15 #3106 - 'Fulltext index on virtual generated column' is not supported for generated columns. | エラー 245
16 問題発生 / ハマった点 / indexを確認 243
17 エラーメッセージ / エラー原因 / エラー対応 239
18 遭遇例1.INT型カラムに空文字INSERT 238
19 #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 ★★ at line △△ | エラー 233
20 phpMyAdmin上で、VARCHARデータ型カラム を FLOATデータ型カラム へ変更しようとしたら、エラー発生 228
2025/4/25 1:01 更新