Table:
fk_case_id page_number page_content
-----------------------------------------------
467 1 Hello
467 2 Good morning
468 1 No need to add
469 1 Welcome
469 2 to home
Python代碼
mycursor.execute(
f"select page_number,page_content,fk_case_id from mt_page_file_contents ORDER BY fk_case_id")
myresult = mycursor.fetchall()
prev_case_id = ""
matchstring = ""
for x in myresult:
page_number = x[0]
text = x[1]
print(text)
需要的解決方案:
1) Hello Good morning
2) No need to add
3) Welcome to home
是否有任何解決方案可以通過基于相同的 fk_case_id 連接兩行來獲得“Hello Good Morning”
uj5u.com熱心網友回復:
您可以 Group BY 并使用 GROUP CONCAT
select
fk_case_id,GROUP_CONCAT(page_content ORDER BY page_number ASC SEPARATOR ' ')
from mt_page_file_contents
GROUP BY fk_case_id
ORDER BY fk_case_id
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/359842.html
