简体   繁体   中英

SQL operator `Greater than` shows inappropriate results

I use this site for learning SQL w3schools . After using SQL statement:

    SELECT * FROM Customers
    WHERE postalcode>05021;                    ------------ formatted codes

I received results with lines where PostalCode == WA1 1DP; S-958 22 and other inappropriate results (from my point of view because they are not integer). Please help me to understand which logic is used here to do this filter. Thanks.

Your postal codes should be stored as strings. Hence, the comparison should be as strings:

SELECT *
FROM Customers
WHERE postalcode > '05021'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM