简体   繁体   English

如何从临时表中应用特定条件的 SELECT 记录?

[英]How to SELECT records from a temp table applying a specific condition?

I have dumped a file into a temp table and trying to pull records where the score is <= 100. The column has values for example, 3, 4.50, 10.02, 99.88,99,99, 100, 100.2, 100, 116, 116.44 etc. I need only 3, 4.50, 10.02,99.88,99,99,100.我已将文件转储到临时表中并尝试提取分数 <= 100 的记录。该列的值例如 3、4.50、10.02、99.88、99、99、100、100.2、100、116、116.44等等。我只需要 3、4.50、10.02、99.88、99、99、100。 When I tried the below, it does not give the proper result.当我尝试以下方法时,它没有给出正确的结果。 Could anyone advise?有人可以建议吗?

SELECT CAST(sum AS numeric ),* FROM temp WHERE sum >= '100' ;

There are two issues here.这里有两个问题。 First, you're using the >= operator instead of the <= operator.首先,您使用的是>=运算符而不是<=运算符。 Second, sum seems to be a string column, so the comparison is performed lexicographically.其次, sum似乎是一个字符串列,因此按字典顺序进行比较。 You could apply the same casting you've applied in the select list and compare the value to a number literal 100 , not a string literal '100' :您可以应用在 select 列表中应用的相同转换,并将值与数字文字100进行比较,而不是字符串文字'100'

SELECT CAST(sum AS numeric ),* FROM temp WHERE CAST(sum AS numeric) >= 100;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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