wiki:WikiStart/AdvancedReports

Version 3 (modified by 121232, 10 months ago) ( diff )

--

Напредни извештаи од базата (SQL и складирани процедури)

1. Листање(приказ) на денешни events, count на денешни часови, испити и tasks:

2. Листање(приказ) на таскови за наредните три дена:

3. Листање(приказ) на испити за наредните седум дена:

4. Листање(приказ) на сите евенти за одредена недела:

DECLARE correct_student_id INT;
SET correct_student_id = 11111;

SELECT *
FROM (
  SELECT 
    ce.calendar_event_id,
    ce.event_name,
    ce.event_type,
    ce.event_start_time,
    ce.event_end_time,
    nre.event_date
  FROM 
    student_event AS se
  JOIN 
    calendar_event AS ce ON se.calendar_event_id = ce.calendar_event_id
  JOIN 
    non_repeating_events AS nre ON ce.calendar_event_id = nre.calendar_event_id
  WHERE 
    nre.event_date >= date_trunc('week', CURRENT_DATE) 
    AND nre.event_date < date_trunc('week', CURRENT_DATE) + INTERVAL '1 week'
    AND se.student_id = correct_student_id

  UNION

  SELECT 
    ce.calendar_event_id,
    ce.event_name,
    ce.event_type,
    ce.event_start_time,
    ce.event_end_time, 
    CASE
      WHEN re.event_week_day = 'MONDAY' THEN date_trunc('week', CURRENT_DATE)::DATE
      WHEN re.event_week_day = 'TUESDAY' THEN date_trunc('week', CURRENT_DATE) + interval '1 day'::DATE
      WHEN re.event_week_day = 'WEDNESDAY' THEN date_trunc('week', CURRENT_DATE) + interval '2 days'::DATE
      WHEN re.event_week_day = 'THURSDAY' THEN date_trunc('week', CURRENT_DATE) + interval '3 days'::DATE
      WHEN re.event_week_day = 'FRIDAY' THEN date_trunc('week', CURRENT_DATE) + interval '4 days'::DATE
      WHEN re.event_week_day = 'SATURDAY' THEN date_trunc('week', CURRENT_DATE) + interval '5 days'::DATE
      WHEN re.event_week_day = 'SUNDAY' THEN date_trunc('week', CURRENT_DATE) + interval '6 days'::DATE
    END AS event_date
  FROM 
    student_event AS se
  JOIN 
    calendar_event AS ce ON se.calendar_event_id = ce.calendar_event_id
  JOIN 
    repeating_events AS re ON ce.calendar_event_id = re.calendar_event_id
  WHERE 
    re.starting_date <= (
      CASE
        WHEN re.event_week_day = 'MONDAY' THEN date_trunc('week', CURRENT_DATE)::DATE
        WHEN re.event_week_day = 'TUESDAY' THEN date_trunc('week', CURRENT_DATE) + interval '1 day'::DATE
        WHEN re.event_week_day = 'WEDNESDAY' THEN date_trunc('week', CURRENT_DATE) + interval '2 days'::DATE
        WHEN re.event_week_day = 'THURSDAY' THEN date_trunc('week', CURRENT_DATE) + interval '3 days'::DATE
        WHEN re.event_week_day = 'FRIDAY' THEN date_trunc('week', CURRENT_DATE) + interval '4 days'::DATE
        WHEN re.event_week_day = 'SATURDAY' THEN date_trunc('week', CURRENT_DATE) + interval '5 days'::DATE
        WHEN re.event_week_day = 'SUNDAY' THEN date_trunc('week', CURRENT_DATE) + interval '6 days'::DATE
      END
    )
    AND re.ending_date >= (
      CASE
        WHEN re.event_week_day = 'MONDAY' THEN date_trunc('week', CURRENT_DATE)::DATE
        WHEN re.event_week_day = 'TUESDAY' THEN date_trunc('week', CURRENT_DATE) + interval '1 day'::DATE
        WHEN re.event_week_day = 'WEDNESDAY' THEN date_trunc('week', CURRENT_DATE) + interval '2 days'::DATE
        WHEN re.event_week_day = 'THURSDAY' THEN date_trunc('week', CURRENT_DATE) + interval '3 days'::DATE
        WHEN re.event_week_day = 'FRIDAY' THEN date_trunc('week', CURRENT_DATE) + interval '4 days'::DATE
        WHEN re.event_week_day = 'SATURDAY' THEN date_trunc('week', CURRENT_DATE) + interval '5 days'::DATE
        WHEN re.event_week_day = 'SUNDAY' THEN date_trunc('week', CURRENT_DATE) + interval '6 days'::DATE
      END
    )
    AND (EXTRACT(day FROM date_trunc('week', CURRENT_DATE) - date_trunc('week', (
        CASE
          WHEN re.event_week_day = 'MONDAY' THEN date_trunc('week', CURRENT_DATE)::DATE
          WHEN re.event_week_day = 'TUESDAY' THEN date_trunc('week', CURRENT_DATE) + interval '1 day'::DATE
          WHEN re.event_week_day = 'WEDNESDAY' THEN date_trunc('week', CURRENT_DATE) + interval '2 days'::DATE
          WHEN re.event_week_day = 'THURSDAY' THEN date_trunc('week', CURRENT_DATE) + interval '3 days'::DATE
          WHEN re.event_week_day = 'FRIDAY' THEN date_trunc('week', CURRENT_DATE) + interval '4 days'::DATE
          WHEN re.event_week_day = 'SATURDAY' THEN date_trunc('week', CURRENT_DATE) + interval '5 days'::DATE
          WHEN re.event_week_day = 'SUNDAY' THEN date_trunc('week', CURRENT_DATE) + interval '6 days'::DATE
        END
      ))) % (7 * re.repeats_every_n_weeks)) = 0
    AND se.student_id = correct_student_id
) AS Result
ORDER BY 
  event_date, -- Order by day of the week
  event_start_time; -- Order by time

5. Листање(приказ) на сите евенти за одреден семестар:

6. Листање(приказ) на сите евенти и task-ови за зададен предмет:

7. Листање(приказ) на сите на сите книги и автори по одреден предмет:

8. Приказна на сите feedbacks (описи и наслови на feedback) со оценка помала од 3:

Note: See TracWiki for help on using the wiki.