› MySQL 5.5 Community Server
› MySQL 5.6 Community Server
› Percona Configuration Wizard
› XtraBackup 搭建主从复制
Great Sites on MySQL
› Percona
› MySQL Performance Blog
› Severalnines
推荐管理工具
› Sequel Pro
› phpMyAdmin
推荐书目
› MySQL Cookbook
MySQL 相关项目
› MariaDB
› Drizzle
参考文档
› http://mysql-python.sourceforge.net/MySQLdb.html
nidalee
V2EX  ›  MySQL

Mysql 8.0 JSON 数据类型的数组如何完全匹配

  •  
  •   nidalee · Jan 10, 2023 · 2251 views
    This topic created in 1355 days ago, the information mentioned may be changed or developed.

    比如数据库有一个 test 表,有 3 条数据

    id num_array
    1 [1,2,3]
    2 [1,2]
    3 [1]

    我想搜索到只包含[1,2]的数据,但是目前看了下网上的一些资料,都没有这种纯数组操作方法的说明

    SELECT * FROM test WHERE JSON_CONTAINS (num_array,'[1,2]')

    返回的数据是

    id num_array
    1 [1,2,3]
    2 [1,2]

    有什么办法执行上面的 sql 可以做到只返回

    id num_array
    2 [1,2]
    nidalee
        1
    nidalee  
    OP
       Jan 10, 2023
    家人们,我悟了
    SELECT * FROM requirement_district WHERE district -> '$[*]' = JSON_ARRAY(1,2)
    这么写就行
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2523 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 15:31 · PVG 23:31 · LAX 08:31 · JFK 11:31
    ♥ Do have faith in what you're doing.