将 CAST() 与 MAX()/MIN() 结合使用

发布于 2024-10-27 10:48:14 字数 496 浏览 2 评论 0原文

我有一些街道号码存储为 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()< /code> 但该语法被拒绝。

DWIM 的正确语法是什么?

I have some street numbers stored as VARCHARs but I want to sort them where possible as INTs. This syntax is accepted but produces alpha sorted sets like 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`

I tried nesting CAST() inside of MIN()/MAX() but that syntax got rejected.

What is the correct sytax to DWIM?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对不⑦ 2024-11-03 10:48:14

这是你尝试过的吗?

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`

Is this what you tried?

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`
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文