HAVING 子句属性

发布于 2024-10-22 03:33:51 字数 749 浏览 1 评论 0原文

我需要这个练习的帮助,我必须将属性从英语翻译成 sql。

问题:

  1. 长度至少有一个0

    答案:MIN(ABS(长度)) = 0
    
  2. length 有多个值

    答案:MIN(长度) <最大(长度)
    
  3. 长度没有空值

    答案:COUNT(*) = COUNT(长度)
    
  4. 长度值要么是正数,要么是负数

    答案:MIN(长度) * MAX(长度) > 0
    
  5. 长度在零以上和以下的差异相同

    答案:MIN(长度) = -max(长度)
    
  6. 所有长度值都不同

    答案:COUNT(DISTINCT 长度) = COUNT(长度)
    
  7. 只有 min(length) 或 max(length) 之一为正

    答案:MIN(长度) * MAX(长度) < 0 
    
  8. length 有一个值或空值

    答案:MIN(长度) = MAX(长度)
    

这些是否正确?我尤其不确定#3、5、6和8。

I need help with this exercise where I have to translate properties from English into sql.

Questions:

  1. length has at least one 0

    Answer: MIN(ABS(length)) = 0
    
  2. length has more that one value

    Answer: MIN(length) < MAX(length)
    
  3. there are no nulls for length

    Answer: COUNT(*) = COUNT(length)
    
  4. values of length are either positive or negative

    Answer: MIN(length) * MAX(length) > 0
    
  5. length differs above and below zero by the same amount

    Answer: MIN(length) = -max(length)
    
  6. all values of length are different

    Answer: COUNT(DISTINCT length) = COUNT(length)
    
  7. only one of min(length) or max(length) is positive

    Answer: MIN(length) * MAX(length) < 0 
    
  8. 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 技术交流群。

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

发布评论

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

评论(2

謌踐踏愛綪 2024-10-29 03:33:51
  1. 长度至少有一个0

    答案:MIN(ABS(长度)) = 0
    
  2. length 有多个值

    答案:MIN(长度) <最大(长度)
    或者
    答案:COUNT(不同长度)> 1
    
  3. 长度没有空值

    答案:COUNT(*) = COUNT(长度)
    
  4. 长度值要么是正数,要么是负数

    答案:MIN(长度) * MAX(长度) > 0
    或者
    更好的答案:Sign(MIN(length)) * Sign(MAX(length)) > 0
    
    -- 因为,对于较大的长度值,将其中的两个相乘
    ——在一起可以给你带来溢出。
    
  5. 长度在零以上和以下的差异相同

    答案:MIN(长度) = -max(长度)
    
  6. 所有长度值都不同

    答案:COUNT(DISTINCT 长度) = COUNT(长度)
    
  7. 只有 min(length) 或 max(length) 之一为正

    可能错误答案:MIN(length) * MAX(length) < 0(0 不是正数)
    或者
    答案:MIN(长度) <= 0 且 MAX(长度) > 0
    
    -- IF:一个必须为正,另一个必须为负
    -- 将 <= 0 更改为 < 0
    
  8. length 有一个值或空值

    错误答案:MIN(length) = MAX(length) -- null=null 不返回 true
    或者
    答案:COUNT(不同长度) <= 1
    
  1. length has at least one 0

    Answer: MIN(ABS(length)) = 0
    
  2. length has more that one value

    Answer: MIN(length) < MAX(length)
    or
    Answer: COUNT(distinct length) > 1
    
  3. there are no nulls for length

    Answer: COUNT(*) = COUNT(length)
    
  4. values of length are either positive or negative

    Answer: MIN(length) * MAX(length) > 0
    or
    Better Answer: Sign(MIN(length)) * Sign(MAX(length)) > 0
    
    -- Because, with large values of length, multiplying two of them
    -- together can give you an overflow.
    
  5. length differs above and below zero by the same amount

    Answer: MIN(length) = -max(length)
    
  6. all values of length are different

    Answer: COUNT(DISTINCT length) = COUNT(length)
    
  7. only one of min(length) or max(length) is positive

    Maybe Wrong Answer: MIN(length) * MAX(length) < 0 (0 is not positive)
    or
    Answer: MIN(length) <= 0 and MAX(length) > 0
    
    -- IF: one must be positive and the other must be negative
    -- change <= 0 to < 0
    
  8. length has one value or null value

    Wrong Answer: MIN(length) = MAX(length) -- null=null does not return true
    or
    Answer: COUNT(distinct length) <= 1
    
我是有多爱你 2024-10-29 03:33:51

我会问#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 in Value2...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文