本文介紹了Mysql 可以拆分列嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有一列包含逗號分隔的數據:
I have a column that has comma separated data:
1,2,3
3,2,1
4,5,6
5,5,5
我正在嘗試運行將分別查詢 CSV 字符串的每個值的搜索.
I'm trying to run a search that would query each value of the CSV string individually.
0<first<5 and 1<second<3 and 2<third<4
我知道我可以返回所有查詢并自己拆分并自己比較.我很好奇是否有辦法做到這一點,以便 mysql 進行處理工作.謝謝!
I get that I could return all queries and split it myself and compare it myself. I'm curious if there is a way to do this so mysql does that processing work. Thanks!
推薦答案
使用
substring_index(`column`,',',1) ==> first value
substring_index(substring_index(`column`,',',-2),',',1)=> second value
substring_index(substring_index(`column`,',',-1),',',1)=> third value
在你的 where 子句中.
in your where clause.
SELECT * FROM `table`
WHERE
substring_index(`column`,',',1)<0
AND
substring_index(`column`,',',1)>5
這篇關于Mysql 可以拆分列嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!