GROUP BY子句中的函数是否必要?
Is the Function in the GROUP BY Clause Necessary?
我是一个正在学习的 Oracle 新手。
以下两个查询的结果是否相同?
查询 1
SELECT
COUNT( customers.id ) AS "id",
customers.full_name AS "name",
customers.cty AS "country",
TO_CHAR( customers.date, 'mm/dd/yyyy' ) AS "date"
FROM customers
GROUP BY
customers.full_name,
customers.cty,
TO_CHAR( customers.date, 'mm/dd/yyyy' );
查询 2:GROUP BY 子句中没有 TO_CHAR()
SELECT
COUNT( customers.id ) AS "id",
customers.full_name AS "name",
customers.cty AS "country",
TO_CHAR( customers.date, 'mm/dd/yyyy' ) AS "date"
FROM customers
GROUP BY
customers.full_name,
customers.cty,
customers.date;
我使用的是 Oracle 12.1 版。
没有。我什至不认为第二个会 运行 因为你的 GROUP BY 与你的 SELECT 不匹配(不包括聚合字段,例如 COUNT(*)
两个查询不会 return 相同的结果...除非 customers.date
只包含没有时间部分的日期。 Oracle 中的 DATE
类型包括日期部分和时间部分。所以相当于一个时间戳。
第一个查询按天分组,第二个查询按 date/hour/minute/second.
我是一个正在学习的 Oracle 新手。
以下两个查询的结果是否相同?
查询 1
SELECT
COUNT( customers.id ) AS "id",
customers.full_name AS "name",
customers.cty AS "country",
TO_CHAR( customers.date, 'mm/dd/yyyy' ) AS "date"
FROM customers
GROUP BY
customers.full_name,
customers.cty,
TO_CHAR( customers.date, 'mm/dd/yyyy' );
查询 2:GROUP BY 子句中没有 TO_CHAR()
SELECT
COUNT( customers.id ) AS "id",
customers.full_name AS "name",
customers.cty AS "country",
TO_CHAR( customers.date, 'mm/dd/yyyy' ) AS "date"
FROM customers
GROUP BY
customers.full_name,
customers.cty,
customers.date;
我使用的是 Oracle 12.1 版。
没有。我什至不认为第二个会 运行 因为你的 GROUP BY 与你的 SELECT 不匹配(不包括聚合字段,例如 COUNT(*)
两个查询不会 return 相同的结果...除非 customers.date
只包含没有时间部分的日期。 Oracle 中的 DATE
类型包括日期部分和时间部分。所以相当于一个时间戳。
第一个查询按天分组,第二个查询按 date/hour/minute/second.