HAVING 子句属性
我需要这个练习的帮助,我必须将属性从英语翻译成 sql。
问题:
长度至少有一个0
答案:MIN(ABS(长度)) = 0
length 有多个值
答案:MIN(长度) <最大(长度)
长度没有空值
答案:COUNT(*) = COUNT(长度)
长度值要么是正数,要么是负数
答案:MIN(长度) * MAX(长度) > 0
长度在零以上和以下的差异相同
答案:MIN(长度) = -max(长度)
所有长度值都不同
答案:COUNT(DISTINCT 长度) = COUNT(长度)
只有 min(length) 或 max(length) 之一为正
答案:MIN(长度) * MAX(长度) < 0
length 有一个值或空值
答案:MIN(长度) = MAX(长度)
这些是否正确?我尤其不确定#3、5、6和8。
I need help with this exercise where I have to translate properties from English into sql.
Questions:
length has at least one 0
Answer: MIN(ABS(length)) = 0
length has more that one value
Answer: MIN(length) < MAX(length)
there are no nulls for length
Answer: COUNT(*) = COUNT(length)
values of length are either positive or negative
Answer: MIN(length) * MAX(length) > 0
length differs above and below zero by the same amount
Answer: MIN(length) = -max(length)
all values of length are different
Answer: COUNT(DISTINCT length) = COUNT(length)
only one of min(length) or max(length) is positive
Answer: MIN(length) * MAX(length) < 0
length has one value or null value
Answer: MIN(length) = MAX(length)
Are these correct? I'm not sure about #3, 5, 6 and 8 in particular.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
长度至少有一个0
length 有多个值
长度没有空值
长度值要么是正数,要么是负数
长度在零以上和以下的差异相同
所有长度值都不同
只有 min(length) 或 max(length) 之一为正
length 有一个值或空值
length has at least one 0
length has more that one value
there are no nulls for length
values of length are either positive or negative
length differs above and below zero by the same amount
all values of length are different
only one of min(length) or max(length) is positive
length has one value or null value
我会问#2。您可能有两个相同的长度值。
对于#3,我不会使用 HAVING 子句来检查非空值。 #4 也是如此。 HAVING 不是根据标量值检查每行的等效性的正确位置。
#5 可能有一些值得措辞的问题。您确定它们意味着最小值和最大值而不是分布吗?
#8 的措辞也很奇怪。 Null 可能是长度值,也可能是没有值。这取决于查询的格式。另外,是否要求您不使用
AND
& 等运算符? <代码>或?此外,大多数数据库平台将 NULL 视为“未知”。由于它是未知的,因此无法检查它是否与另一个值相等。如果您不知道
Value1
是什么,您就不可能知道它是否与Value2
中的内容相同...I would question #2. You may have two identical length values.
For #3, I would not use the HAVING clause to check for non-nulls. Same thing for #4. HAVING is not the right place to be checking equivalency for each row against a scalar value.
#5 might have some problems worth wording. Are you certain they mean min and max and not distribution?
#8 is oddly worded as well. Null could be the value of length, or it could be absence of value. It depends on how the query is formated. Also, is there a requirement that you not use operators like
AND
&OR
?Also, NULL is treated as "unknown" with most database platforms. Since it is unknown, it cannot be checked for equivalency against another value. If you don't know what
Value1
is, you can't possibly know if it's the same as what's inValue2
...