SQL查询报告我认为使用最小汇总以及操作员过滤的最小值是错误的最小值

发布于 2025-01-24 11:30:07 字数 350 浏览 2 评论 0原文

我正在参加Coursera的SQL课程,这个问题在练习测验中提出了

“不包括0.00美元,最低每两周一周的高薪率是多少(请在您的答案中包括美元标志和小数点)?

现在我得到了正确的答案(返回$ 100.00)

SELECT 
    min(Biweekly_High_Rate)
FROM
    salary_range_by_job_classification
WHERE Biweekly_High_Rate <> '$0.00'

但是,当我从同一表中查询选择 *时,我可以看到,至少在回收的行中,有一个$ 15.00的值,为什么不小于$ 100.00。返回$ 15.00?

I am taking an SQL course on coursera and this question came up on a practice quiz

"Excluding $0.00, what is the minimum bi-weekly high rate of pay (please include the dollar sign and decimal point in your answer)?

Now I got the right answer (Which returned $100.00) using

SELECT 
    min(Biweekly_High_Rate)
FROM
    salary_range_by_job_classification
WHERE Biweekly_High_Rate <> '$0.00'

however, when I query using SELECT * from the same table, I can see that, at least in the rows retrieved, that there is a value of $15.00 which is less than $100.00. Why is it not returning $15.00? table snip of SELECT * FROM salary_range_by_job_classification

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

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

发布评论

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

评论(2

寄人书 2025-01-31 11:30:07

我建议删除美元标志,然后将结果字符串转换为小数额。还输入十进制数量作为限制参数(0.00),因此您要比较两个数字,而不是两个字符串。这应该导致更多的期望:

SELECT MIN(CONVERT(DECIMAL(10,2),REPLACE(BiWeekly_High_Rate,'

看看情况如何。如果您比较两个字符串,则使用 min 聚合要求(我认为)(我认为)第一个值字母

,''))) FROM salary_range_by_job_classification WHERE CONVERT(DECIMAL(10,2),REPLACE(BiWeekly_High_Rate,'

看看情况如何。如果您比较两个字符串,则使用 min 聚合要求(我认为)(我认为)第一个值字母

,'')) <> 0.00

看看情况如何。如果您比较两个字符串,则使用min聚合要求(我认为)(我认为)第一个值字母

I would recommend removing the dollar sign and converting the resultant string to a decimal amount. Enter a decimal amount as your limiting parameter (0.00) as well, so you are comparing two numbers, not two strings. This should result in something more expected:

SELECT MIN(CONVERT(DECIMAL(10,2),REPLACE(BiWeekly_High_Rate,'

See how that goes. If you compare two strings, you are asking for (I think) the first value alphabetically by using the MIN aggregation.

,''))) FROM salary_range_by_job_classification WHERE CONVERT(DECIMAL(10,2),REPLACE(BiWeekly_High_Rate,'

See how that goes. If you compare two strings, you are asking for (I think) the first value alphabetically by using the MIN aggregation.

,'')) <> 0.00

See how that goes. If you compare two strings, you are asking for (I think) the first value alphabetically by using the MIN aggregation.

瑕疵 2025-01-31 11:30:07

您可以尝试一下。

SELECT Min(Cast(Replace(biweekly_high_rate, '
, '') AS REAL))
FROM   salary_range_by_job_classification
WHERE  biweekly_high_rate <> '$0.00' 

You can try this.

SELECT Min(Cast(Replace(biweekly_high_rate, '
, '') AS REAL))
FROM   salary_range_by_job_classification
WHERE  biweekly_high_rate <> '$0.00' 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文