[英]selecting the minimum amount records where the sum is greater than a certain number
[英]Delete records using sql ,if it is greater than certain number with an unit attached to it (eg 3M or 3cm)
让一张桌子成为“酒店”,有一列:
酒店价值 |
---|
15M |
4M |
8M |
3M |
1M |
2M |
11M |
如何使用 sql 删除表中的记录,其中价值大于 3M。
在DELETE
语句的WHERE
子句中,您可以通过添加0
将字符串转换为数值:
DELETE FROM hotel
WHERE hotel_worth + 0 > 3
如果您只想删除后缀为M
的行(如果还有其他后缀),请添加:
AND RIGHT(hotel_worth, 1) = 'M'
这可以通过使用来完成:
DELETE FROM price
WHERE SUBSTR(`hotel_worth`, 1, LENGTH(`hotel_worth`) - 1) + 0 > 3
解释:子substr
:
SUBSTR(`hotel_worth`, 1, LENGTH(`hotel_worth`) - 1)
检索不包括最后一个字符的列的数据,即(从 10M 到 10),然后 + 0 将其转换为 int。
所以最后的> 3
比较基本上就是选择大于3M的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.