我有一个表宽行,有两个日期,一个提醒日期和一个结束日期。我希望根据两个日期将这些事件放在日历中,所以我需要按两个日期字段按顺序选择每一行两次。有没有办法做到这一点?
答案 0 :(得分:0)
我会尝试像
这样的东西SELECT CalendarID,
CalendarName,
CalendarDescription,
ReminderDate EntryDate,
'Reminder' EntryType
FROM Calendar
WHERe ReminderDate = YourDate
UNION ALL
SELECT CalendarID,
CalendarName,
CalendarDescription,
EndDate EntryDate,
'End' EntryType
FROM Calendar
WHERe EndDate = YourDate
第一部分将带回提示日期在指定日期的所有条目,第二部分将带回所有具有指定结束日期的条目。
您还可以将where子句更改为
之间类似
SELECT CalendarID,
CalendarName,
CalendarDescription,
ReminderDate EntryDate,
'Reminder' EntryType
FROM Calendar
WHERe ReminderDate BETWEEN YourLookupStartDate and YourLookupEndDate
UNION ALL
SELECT CalendarID,
CalendarName,
CalendarDescription,
EndDate EntryDate,
'End' EntryType
FROM Calendar
WHERe ReminderDate BETWEEN YourLookupStartDate and YourLookupEndDate
答案 1 :(得分:0)
这可能会有所帮助
SELECT column_name
FROM table_name
WHERE column_name BETWEEN Remainderdate AND Enddate;
答案 2 :(得分:0)
使用以下查询
SELECT * FROM table1 as a
INNER JOIN table1 as b ON a.id = b.id
WHERE a. reminder_date = 'reminder_date_here' and b. end_date ='end_date_here'