如何在 MySQL 5.7 中統計 JSON 數組中特定值的計數?

如何在 MySQL 5.7 中統計 JSON 數組中特定值的計數?

如何在 mysql 5.7 中統計 json 數組中特定值的計數

mysql 5.7 中無法使用 json_table 函數統計 json 數組中特定值的計數。一種替代方法是使用 json_search 函數,如下所示:

SELECT     count( JSON_SEARCH( tags, 'one', "3467562849402896" ) ),     count( JSON_SEARCH( tags, 'one', "3467562861985809" ) ),     count( JSON_SEARCH( tags, 'one', "3465044211793921" ) ) FROM     XXXXXXXXXX

在這個查詢中:

  • xxxxxxxxxx 是包含 json 列 tags 的表名。
  • json_search 函數用于在 tags 數組中查找特定值(在本例中為 “3467562849402896”、”3467562861985809″ 和 “3465044211793921”)。
  • count 函數計算每個值的出現次數。

? 版權聲明
THE END
喜歡就支持一下吧
點贊6 分享