我通過Python(pymysql)查詢MySQL數據庫(fintech_16
)以獲得列的唯一值(Trend
)。當我跑到下面的查詢:MySQL通過逗號分隔列值
cursor.execute ("SELECT DISTINCT `Trend` FROM `fintech_16` ")
cursor.fetchall()
我得到了以下結果:
((u'Investments',),
(u'Expansion',),
(u'New Products',),
(u'Collaboration',),
(u'New Products,Investments',),
(u'New Products,Expansion',),
(u'Expansion,Investments',),
(u'New Products,Collaboration',),
(u'Regulations',),
(u'Investments,New Products',),
(u'Investments,Expansion',),
(u'Collaboration,Investments',),
(u'Expansion,New Products',),
(u'Collaboration,New Products',))
現在。由於一些ID有不止一種趨勢,因此數據庫將它們視爲單獨的趨勢。
我應該如何調整我的查詢以獲得僅有的趨勢(投資,擴張,新產品,合作,規章)以及他們的數量?
雖然這些只有5個,但我可以使用LIKE %Investments%
來手動獲取計數,但我希望代碼/查詢能夠執行此操作。
TIA
什麼是您預期的輸出。編輯並將其添加到上面的問題。 –
GIGO。見正常化。 – Strawberry