1
我有兩個表。一個是TblPeople(ID(PK),名,姓,Embo ..)和其他是TBLembolization(EmbolizationID(PK),PeopleID(FK),EmbolizationDate,在單行顯示重複的行mysql
這是我的查詢,使用名稱...
SELECT tblpeople.FirstName,details.peopleID,details.embolizationDate FROM tblpeople
LEFT JOIN tblembolizations AS details ON tblpeople.ID=details.peopleID
WHERE tblpeople.Embo = 1 and concat(FirstName,' ',LastName) like '%alina%'
UNION
SELECT tblpeople.FirstName,details.peopleID,details.embolizationDate FROM tblpeople
LEFT JOIN tblembolizations AS details ON tblpeople.ID=details.peopleID
WHERE tblpeople.Embo != 1 and concat(' ',FirstName,' ',LastName,' ') like '%alina%'
結果是:
............Result .......................
FirstName |peopleID|embolizationDate
Alina |16,459 |2017-27-03
Alina | 16,459 |2017-24-03
Alina D. | 14,499 |2017-27-09
======================================
可以看到,阿麗娜擁有像她那樣的栓塞上兩個日期的多個紀錄,我想它在單一的記錄,如果有人做了栓塞超過1次,所以我想要它這樣的一些事情
............Result .......................
FirstName |peopleID|embolizationDate|2ndembolization
Alina |16,459 |2017-27-03 |2017-24-03
Alina D. | 14,499 |2017-27-09
======================================
如果有人不止一次地完成了栓塞並且只有一次栓塞的時間比記錄以正確的方式進行了一次,那麼是否有可能在單一記錄中得到答案。 謝謝
謝謝你的工作:) –