插入一列以不同的药物治疗
我有一个包含耐心治疗日期的数据库,如下所示:
pacient_id | date | type | finish
1 | 2021-01-05 | routine | null
1 | 2021-01-10 | routine | null
1 | 2021-01-22 | routine | null
1 | 2021-01-30 | routine | yes
1 | 2021-02-04 | routine | null
1 | 2021-02-12 | routine | null
1 | 2021-02-19 | routine | null
1 | 2021-02-22 | routine | yes
我需要在查询中添加一个新列,以显示咨询是第一次治疗还是第二次治疗,例如:
pacient_id | date | type | finish | treatment
1 | 2021-01-05 | routine | null | 1
1 | 2021-01-10 | routine | null | 1
1 | 2021-01-22 | routine | null | 1
1 | 2021-01-30 | routine | yes | 1
1 | 2021-02-04 | routine | null | 2
1 | 2021-02-12 | routine | null | 2
1 | 2021-02-19 | routine | null | 2
1 | 2021-02-22 | routine | yes | 2
当完成列=是时,则治疗完成。该表有很多 pacients:
pacient_id | date | type | finish
1 | 2021-01-05 | routine | null
2 | 2021-01-10 | routine | null
5 | 2021-01-22 | routine | null
2 | 2021-01-30 | routine | yes
1 | 2021-02-04 | routine | null
3 | 2021-02-12 | routine | null
9 | 2021-02-19 | routine | null
1 | 2021-02-22 | routine | yes
所以我订购 pacient_id 和日期。感谢您的帮助。
I have a database with the dates of pacient treatment like this:
pacient_id | date | type | finish
1 | 2021-01-05 | routine | null
1 | 2021-01-10 | routine | null
1 | 2021-01-22 | routine | null
1 | 2021-01-30 | routine | yes
1 | 2021-02-04 | routine | null
1 | 2021-02-12 | routine | null
1 | 2021-02-19 | routine | null
1 | 2021-02-22 | routine | yes
I need a new column on a query that show if the consults are of first treatment or of second, example:
pacient_id | date | type | finish | treatment
1 | 2021-01-05 | routine | null | 1
1 | 2021-01-10 | routine | null | 1
1 | 2021-01-22 | routine | null | 1
1 | 2021-01-30 | routine | yes | 1
1 | 2021-02-04 | routine | null | 2
1 | 2021-02-12 | routine | null | 2
1 | 2021-02-19 | routine | null | 2
1 | 2021-02-22 | routine | yes | 2
When the finish column = yes, then the treatment is finish. The table have many pacients:
pacient_id | date | type | finish
1 | 2021-01-05 | routine | null
2 | 2021-01-10 | routine | null
5 | 2021-01-22 | routine | null
2 | 2021-01-30 | routine | yes
1 | 2021-02-04 | routine | null
3 | 2021-02-12 | routine | null
9 | 2021-02-19 | routine | null
1 | 2021-02-22 | routine | yes
So I order to pacient_id and date. Thanks for help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
在 dbfiddle 中查看测试结果
Try this :
see test result in dbfiddle