我有一些街道号码存储为VARCHAR但我想尽可能将它们作为INT排序。接受此语法但生成alpha排序集,如max = 53,min = 1203
SELECT `StreetName`,
CAST( MIN( `StreetNumber` ) AS UNSIGNED) as min,
CAST( MAX( `StreetNumber` ) AS UNSIGNED) as max
FROM `tblAddToLotBridge`
WHERE `LotNumber` = '$item_lotnum'
AND `Primary_Secondary` = 0
GROUP BY `StreetName`
ORDER BY `StreetName`
我尝试在CAST()
/ MIN()
内嵌套MAX()
,但该语法被拒绝了。
DWIM的正确sytax是什么?
答案 0 :(得分:8)
这是你试过的吗?
SELECT `StreetName`,
MIN( CAST( `StreetNumber` AS UNSIGNED) ) as min,
MAX( CAST( `StreetNumber` AS UNSIGNED) ) as max
FROM `tblAddToLotBridge`
WHERE `LotNumber` = '$item_lotnum'
AND `Primary_Secondary` = 0
GROUP BY `StreetName`
ORDER BY `StreetName`