![](/img/trans.png)
[英]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.