【问题标题】:How i can get these from database using mysql?我如何使用mysql从数据库中获取这些?
【发布时间】:2012-11-28 12:20:12
【问题描述】:

我有一张桌子,上面有 like did 和 patientid。这里做的是医生ID,病人ID是给病人的。

现在我要根据医生的要求来检索记录。

这里的查询是患者​​ ID,例如 12/2456。这里的 12 表示 2012 年。

我如何获取所有 id 只剩下 12(年)的行?

这样可以捡起来吗?

桌子就像

did pid 
101 12/3492
101 12/6789

现在需要像

这样的输出
did pid 
101 3492
101 6789

【问题讨论】:

    标签: mysql sql select substring


    【解决方案1】:

    试试这个:

    select did , substring_index(pid ,'/',-1) pid from table 
    

    【讨论】:

      【解决方案2】:

      或者,您可以像这样构建函数:

      SELECT did, RIGHT(pid, LENGTH(pid) - LOCATE('/',pid)) pid
      FROM Table
      

      【讨论】:

        【解决方案3】:

        我认为这会有所帮助

        select did,SUBSTRING_INDEX(patient id, '/', -1) pid
        from table_name
        

        【讨论】:

          猜你喜欢
          • 2019-11-08
          • 1970-01-01
          • 2015-09-18
          • 1970-01-01
          • 2017-09-20
          • 1970-01-01
          • 2021-06-10
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多