doujianchao7446 2017-11-06 15:50
浏览 550

mysql数据库如何处理包含多个值的字段

i have MYSQL database where a table have a field that contains multiple values in each cell. where these values are a foreign key of another table.

inspection_date:

  • siteID (primary key)
  • employeeID(foreign key)
  • inspectionDate

where the emplyee field will have multiple values be cause more than one employee had done the inspection.

employee

  • employeeID(primary key)
  • employeeName

can anyone help me to use select query

mysql :

$query_site_location =$wpdb->get_results("select DISTINCT 
                      l.siteID,
                      l.locationName, 
                      n.inspectionDate,
                      s.employeeID
                       from site_location l
                       LEFT    
                       JOIN inspection_info n
                       on l.siteID = n.siteID
                       LEFT  
                       JOIN employee s
                       on n.employeeID = s.employeeID");

the result must be in the field of employee (6-7) for the first row

  • 写回答

1条回答 默认 最新

  • dqbjvg2518 2017-11-08 13:28
    关注

    A THIS relation is many to many we must create a third entity in order to handle the primary keys of both tables.

    employee:

    employeeID(PRIMARY KEY)
    employeeName
    

    inspection_info:

    inspectionID(PRIMARY KEY)
    inspectionDate
    employeeID
    

    inspection_site:

    inspectionID(PRIMARY KEY)
    
    siteID(PRIMARY KEY)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计