这几天在做sql编译相关的东西, 自己弄了个题目,连资深数据库开发人员都可能会搞错. 以下sql中哪些执行时会报错? (适于所有常见DBMS)
1.
select
distinct col
from
tbl
2.
select
distinct col1,
distinct col2
from
tbl
3.
select
count(distinct col% 10)
from
tbl
4.
select
length(distinct col1% 10)
from
tbl
5.
select
sum(distinct col1% 10),
sum(distinct col1% 9)
from
tbl
6.
select
distinct col1,
count(distinct col2)
from
tbl
7.
select
sum(distinct col1 % 10),
count(distinct col2 % 9)
from
tbl
8.
select
max(distinct substr(col1, 1, 10)),
count(distinct col2 % 9)
from
tbl
本文通过一系列 SQL 查询示例探讨了使用 DISTINCT 关键字时可能遇到的问题及错误情况,适用于多种数据库管理系统。从简单的 DISTINCT 列到复杂的聚合函数,帮助读者深入理解 DISTINCT 的正确用法。

被折叠的 条评论
为什么被折叠?



