我有一个MySQL表: 组合列是JSON数据类型
id | combo
1 | {"qty": "2", "variations": [{"name": "Cover", "value": "Paperback"}], "price": "14.00"}
2 | {"qty": "1", "variations": [{"name": "Cover", "value": "Hardback"}], "price": "7.00"}
3 | {"qty": "1", "variations": [{"name": "Cover", "value": "Paperback"}], "price": "15.00"}
我试图获得MIN()
7.00
的价格但是因为它们是字符串,它会返回14.00
。
可以这样做吗?这就是我的尝试:
SELECT
JSON_UNQUOTE(MIN(combo->'$.price')) AS min_price
FROM itemListings
GROUP BY id
我也尝试删除存储价格周围的报价,但结果相同。
答案 0 :(得分:1)
您的代码为您提供词典最低要求;在排序字符串时,"1"
位于"7"
之前,尽管字符串为"14.00"
和"7:00"
,但"apple"
就像"bat"
之前的"apple"
一样"bat"
超过SELECT
id, -- you probably want the select the grouped by value too
MIN(CAST(combo->'$.price' AS DECIMAL(10,2))) AS min_price
FROM itemListings
GROUP BY id
。
您希望数字最小,因此将值转换为十进制数字:
var myFilterPredictions = [GMSAutocompletePrediction]()