获取 MI:SSSS 精度的计数?
Obtain count to MI:SSSS precision?
TRANSACTION_DATE 是 DATE 数据类型。
此代码列出了 MI:SSSS 的所有事件日期。
select to_char(transaction_date,'YYYY-MON-DD HH24:MI:SSSS') as trans_date from ticket_orders;
现在我想获取这些日期的计数,但我得到的是 ORA-00979 而不是 GROUP BY 函数。
select to_char(transaction_date,'YYYY-MON-DD HH24:MI:SSSS') as trans_date,
count(*)
from ticket_orders
group by to_char(transaction_date,'YYYY-MON-DD HH24:MI:SSSS');
错误 ORA-00979: not a GROUP BY expression
如何获得 MI:SSSS
精度的交易计数?
DATE
数据类型不存储小数秒。您可以参考Oracle documentation about data types.
DATE
Valid date range from January 1, 4712 BC, to December 31, 9999 AD. The
default format is determined explicitly by the NLS_DATE_FORMAT
parameter or implicitly by the NLS_TERRITORY parameter. The size is
fixed at 7 bytes. This data type contains the datetime fields YEAR,
MONTH, DAY, HOUR, MINUTE, and SECOND. It does not have fractional
seconds or a time zone.
如果您想要存储小数秒的数据类型,则需要使用 TIMESTAMP
TIMESTAMP [(fractional_seconds_precision)]
Year, month, and day values of date, as well as hour, minute, and
second values of time, where fractional_seconds_precision is the
number of digits in the fractional part of the SECOND datetime field.
Accepted values of fractional_seconds_precision are 0 to 9. The
default is 6. The default format is determined explicitly by the
NLS_TIMESTAMP_FORMAT parameter or implicitly by the NLS_TERRITORY
parameter. The size is 7 or 11 bytes, depending on the precision. This
data type contains the datetime fields YEAR, MONTH, DAY, HOUR, MINUTE,
and SECOND. It contains fractional seconds but does not have a time
zone.
一种DATE
数据类型是一种二进制数据类型,由7个字节组成,分别代表世纪、year-of-century、月、日、时、分、秒。它 ALWAYS 具有这些组件,它 NEVER 包含小数秒(即 TIMESTAMP
数据类型可以有小数秒 and/or时区信息).
If DATE
type does not store fractional seconds, why does a typical row from my first query look like this 2021-FEB-25 07:58:2626
那是因为您两次使用 SS
格式模型显示秒数。
您的查询可以是:
select to_char(transaction_date,'YYYY-MON-DD HH24:MI:SS') as trans_date,
count(*)
from ticket_orders
group by
transaction_date;
db<>fiddle here
TRANSACTION_DATE 是 DATE 数据类型。
此代码列出了 MI:SSSS 的所有事件日期。
select to_char(transaction_date,'YYYY-MON-DD HH24:MI:SSSS') as trans_date from ticket_orders;
现在我想获取这些日期的计数,但我得到的是 ORA-00979 而不是 GROUP BY 函数。
select to_char(transaction_date,'YYYY-MON-DD HH24:MI:SSSS') as trans_date,
count(*)
from ticket_orders
group by to_char(transaction_date,'YYYY-MON-DD HH24:MI:SSSS');
错误 ORA-00979: not a GROUP BY expression
如何获得 MI:SSSS
精度的交易计数?
DATE
数据类型不存储小数秒。您可以参考Oracle documentation about data types.
DATE
Valid date range from January 1, 4712 BC, to December 31, 9999 AD. The default format is determined explicitly by the NLS_DATE_FORMAT parameter or implicitly by the NLS_TERRITORY parameter. The size is fixed at 7 bytes. This data type contains the datetime fields YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND. It does not have fractional seconds or a time zone.
如果您想要存储小数秒的数据类型,则需要使用 TIMESTAMP
TIMESTAMP [(fractional_seconds_precision)]
Year, month, and day values of date, as well as hour, minute, and second values of time, where fractional_seconds_precision is the number of digits in the fractional part of the SECOND datetime field. Accepted values of fractional_seconds_precision are 0 to 9. The default is 6. The default format is determined explicitly by the NLS_TIMESTAMP_FORMAT parameter or implicitly by the NLS_TERRITORY parameter. The size is 7 or 11 bytes, depending on the precision. This data type contains the datetime fields YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND. It contains fractional seconds but does not have a time zone.
一种DATE
数据类型是一种二进制数据类型,由7个字节组成,分别代表世纪、year-of-century、月、日、时、分、秒。它 ALWAYS 具有这些组件,它 NEVER 包含小数秒(即 TIMESTAMP
数据类型可以有小数秒 and/or时区信息).
If
DATE
type does not store fractional seconds, why does a typical row from my first query look like this2021-FEB-25 07:58:2626
那是因为您两次使用 SS
格式模型显示秒数。
您的查询可以是:
select to_char(transaction_date,'YYYY-MON-DD HH24:MI:SS') as trans_date,
count(*)
from ticket_orders
group by
transaction_date;
db<>fiddle here