dov11020 2010-05-16 09:03
浏览 90

SQL字符串替换为ID语句

Is it possible to create a sql statement to do the following:

Table 1 lists all of the drug names, Table 2 contains all of the side effects.

Table 3 contains all the drug names by ID and all of the side effects separated by |.

Is there some kind of SQL query I can run to re-create Table 3 where the side effects separated by | are the side effect ID's from Table 2?

Table1
---------------------
id | drug_name
---------------------
1  | aspirin
2  | zoloft
3  | codine


Table2
---------------------
id | side_effects
---------------------
1  | rash
2  | hearing loss
3  | the plague


Table3
---------------------
id | drugs2sidefx
---------------------
1  | rash | hearing loss
2  | 
3  | the plague | hearing loss
  • 写回答

1条回答 默认 最新

  • dongziduo9762 2010-05-16 09:19
    关注

    You don't need table3 this way.

    it should be

    drugs2se
    ---------------------
    d_id | se_id
    ---------------------
    1    |  1
    1    |  2
    3    |  2
    3    |  3
    

    Then you can get desired results with a query like this

    SELECT d.name, group_concat(se.name) as effects 
    FROM drugs d, drugs2se dse, side_effects se 
    WHERE d.id=d_id AND se_id=se.id 
    GROUP BY (d.id)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么