如何在此查询中获取每天的最大(小时)和最小(小时)?
技术问答
242 人阅读
|
0 人回复
|
2023-09-12
|
我有表日记的结构:3 e% Y8 Y5 l3 g% ^1 K; R
CREATE TABLE Diary( [IdDiary] bigint, [IdDay] numeric(18,0));INSERT INTO Diary ([IdDiary],[IdDay])values (51,1),(52,2),(53,5);表DiaryTimetable的其他结构:
) \* v/ u e) c! K% v4 Y. i. ? CREATE TABLE DiaryTimetable( [IdDiary] bigint, [Hour] varchar(50); INSERT INTO DiaryTimetable ([IdDiary],[Hour])VALUES (51,09:00), (51,09:30), (51,'10:00), (51,'10:30), (51,'11:00), (51,'11:30), (52,'11:00), (52,'11:30), (52,'11:300), (52,'12:30), (53,'16:30);表Diary包含一个IdDiary,而IdDay例如:
, e$ ]+ T3 D) LMonday --> 1Tuesday --> 2Wednesday --> 3Thursday --> 4Friday --> 5Saturday --> 6Sunday --> 7表DiaryTimetable包含iddiary和小时。我想得到它DiaryTimetable如果表中每天出现的最大小时和最小时出现在表中Diary在表中,如果我输入此查询,结果将只是所有查询的最大小时和最小时:8 Y7 }/ Y; b( r9 l- W8 E6 U
select MAX(Hour),MIN(Hour) from DiaryTimetableinner join Diary onDiaryTimetable.IdDiary = Diary.IdDiary我需要的wat结果将如下:
8 P" {4 l& z; d* a8 LIdDiary IdDay Min Hour Max Hour----- ----- -------- ---------51 11:300 55:0015:300 16:300 16:30谢谢你,我怎么得到这个?, C* q' I8 e. v
SQL现场演示1 C& }6 y* y W$ Q/ I! o& T
s4 ]( c) e/ f- a3 W6 N% P2 y6 B3 H' e
解决方案: |
|
|
|
|
|