Changes between Version 3 and Version 4 of Advanced database reports (SQL and Stored procedures)


Ignore:
Timestamp:
12/21/22 16:54:12 (2 years ago)
Author:
201101
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Advanced database reports (SQL and Stored procedures)

    v3 v4  
    1717== Вкупен број на настани во последните 6 месеци, вкупен број на гости на настаните, просечна цена на настан по гостин и вкупен промет од сите настани
    1818
     19{{{#!sql
    1920select   count(e.event_id) as num_events, 
    2021         sum(e.number_of_interested_guests) as total_guests,
     
    2829join events e on
    2930rfe.event_id  = e.event_id
     31}}}
    3032
    3133== Вкупен број на активности во последната година, вкупен број на гости на активностите, просечна цена на активност по гостин и вкупен промет од сите активности
    3234
     35{{{#!sql
     36select   count(a.activity_id) as num_activities, 
     37         sum(a.number_of_interested_guests) as total_guests,
     38         avg(a.price) as avg_price,
     39         sum(a.price * a.number_of_interested_guests) as sales
     40from reservation_for_activity rfa
     41join reservation r on
     42rfa.reservation_id = r.reservation_id
     43and
     44(start_date between now() - interval '1 year' and now())
     45join activities a  on
     46rfa.activity_id  = a.activity_id
     47}}}
     48
    3349== Просечна плата на секој тип на вработени во Вила Дихово
     50
     51{{{#!sql
     52select
     53        (
     54          select count(w.user_id)
     55          from waiter w
     56        )as waiters_in_villa_dihovo,
     57        (
     58          select avg(w.salary)
     59          from waiter w
     60        )as average_salary_waiter,
     61        (
     62          select count(r.user_id)
     63          from receptionist r
     64        )as receptionists_in_villa_dihovo,
     65        (
     66          select avg(r.salary)
     67          from receptionist r
     68        )as average_salary_receptionist,
     69        (
     70          select count(c.user_id)
     71          from chef c
     72        ) as chefs_in_villa_dihovo,
     73        (
     74          select avg(c.salary)
     75          from chef c
     76        )as average_salary_chef
     77
     78from user_table ut
     79group by 1,2,3;
     80}}}
    3481
    3582== Број на соби во секоја вила
    3683
     84{{{#!sql
     85select v.name as villa_name ,
     86       count(r.room_id) as number_of_rooms
     87    from villa v
     88    join rooms r on
     89    r.villa_id  = v.villa_id
     90    group by villa_name
     91    order by villa_name
     92}}}
     93
    3794== Нарачки за храна кој ги има направено еден корисник и вкупна сума на плаќање
     95
     96{{{#!sql
     97select pm.user_id,
     98       ut.full_name,
     99       count(ut.full_name) as broj_naracki_hrana,
     100       sum(rfpm.quantity * m.price) as total_sum
     101from prepared_meal pm
     102join user_table ut on
     103pm.user_id  = ut.user_id
     104join meal m on
     105pm.meal_id  = m.meal_id
     106join reservation_for_prepared_meal rfpm on
     107rfpm.prepared_meal_id  = pm.prepared_meal_id
     108join reservation r on
     109rfpm.reservation_id  = r.reservation_id
     110group by 1,2
     111}}}