遭遇例1

MySQL用語集

カテゴリー: エラー  閲覧数:284 配信日: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」も、一意かどうかの判定に利用されるため注意が必要

週間人気ページランキング / 4-17 → 4-23
順位 ページタイトル抜粋 アクセス数
1 MySQL用語 7
2026/4/24 5:05 更新
指定期間人気ページランキング / 2020-5-28 → 2026-4-23
順位 ページタイトル抜粋 アクセス数
1 #1241 - オペランドに 1 個の列が必要です。 | エラー 3776
2 MySQL用語 1612
3 クエリエラー: #1265 - 列 'カラム名' の 行 ★ でデータが切り捨てられました。 | エラー 1428
4 SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry | エラー 1394
5 ( ! ) Fatal error: Uncaught PDOException: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value | エラー 1010
6 Data truncated for column | エラー 665
7 Incorrect integer value | 「エラー」カテゴリー | MySQL用語 637
8 where clause is ambiguous | エラー 635
9 クエリエラー: #1294 - 列 'カラム名' に ON UPDATE旬は無効です。 | エラー 630
10 <> | 演算子 481
11 スキーマ | データベースの構造 458
12 #1067 - Invalid default value for 'id' | エラー 432
13 インデックス | 最適化 408
14 SELECT list is not in GROUP BY clause and contains nonaggregated column | 「エラー」カテゴリー | MySQL用語 276
14 遭遇例1.INT型カラムに空文字INSERT 276
15 エラーメッセージ / エラー原因 / エラー対応 266
16 #3106 - 'Fulltext index on virtual generated column' is not supported for generated columns. | エラー 263
17 #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 △△ | エラー 244
17 問題発生 / ハマった点 / indexを確認 244
18 phpMyAdmin上で、VARCHARデータ型カラム を FLOATデータ型カラム へ変更しようとしたら、エラー発生 241
2026/4/24 5:05 更新