在 MySQL 中,我有一个表,其中一个字段的类型是 TIME(字段 HORA):
通过提供这样的选择:
SELECT hora FROM tabela GROUP BY hora
没有返回任何内容,如果我在任何其他字段中进行 GROUP BY,则它有效。这种行为有意义吗?如果是这样,如何将相同的结果分组?
答案 0 :(得分:0)
时间排序有效
declare @tmp as table(id int, name varchar(20), hora time)
insert into @tmp
(id,name, hora)
values
(1,'andre','07:00:00'),
(2,'caio','06:00:00'),
(3,'carlos','07:00:00'),
(4,'andre','09:00:00')
select * from @tmp
order by hora desc
输出:
id name hora
4 andre 09:00:00.0000000
3 carlos 07:00:00.0000000
1 andre 07:00:00.0000000
2 caio 06:00:00.0000000
答案 1 :(得分:-1)
delete
Select *
from hora
group by hora
order by hora ASC;
这应该返回 hora 列中的所有行。如果仍然存在差异,则表列的格式可能存在问题。
https://popsql.com/learn-sql/sql-server/how-to-group-by-time-in-sql-server