Changes between Initial Version and Version 1 of AdvancedReports


Ignore:
Timestamp:
01/22/24 15:04:28 (12 months ago)
Author:
175012
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AdvancedReports

    v1 v1  
     1= Напредни извештаи од базата (SQL и складирани процедури) =
     2
     3=== Извештај за сите податоци за клиент, возило, осигурител, почетен датум, краен датум===
     4
     5{{{#!sql
     6
     7WITH CustomerPolicyInfo AS (
     8    SELECT
     9        c.c_id,
     10        c.name AS customer_name,
     11        c.email,
     12        c.type AS customer_type,
     13        p.sdate,
     14        p.edate,
     15        pd.d_embg,
     16        pd.name AS policy_holder_name,
     17        pd.surname AS policy_holder_surname,
     18        pt.title AS package_title,
     19        pt.total AS package_total,
     20        p.p_id as policy_id
     21    FROM
     22        project.Customer c
     23    INNER JOIN project.Pol_dog pd ON c.c_id = pd.c_id
     24    INNER JOIN project.Policy p ON pd.policy = p.p_id
     25    INNER JOIN project.Package pt ON p.package = pt.code
     26)
     27SELECT
     28    cpi.c_id,
     29    cpi.customer_name,
     30    cpi.email,
     31    cpi.customer_type,
     32    cpi.sdate,
     33    cpi.edate,
     34    cpi.d_embg,
     35    cpi.policy_holder_name,
     36    cpi.policy_holder_surname,
     37    cpi.package_title,
     38    cpi.package_total,
     39    cpi.policy_id,
     40CASE
     41    WHEN po.o_embg IS NOT NULL THEN 'Travel Health'
     42    ELSE 'Auto registration'
     43END AS policy_type,
     44    po.o_embg AS osi_embg,
     45    po.name AS osi_name,
     46    po.surname AS osi_surname,
     47    po.birthdate AS osi_birthdate,
     48    po.kontakt AS osi_kontakt,
     49    v."type"  AS vehicle_type,
     50    v.marka  AS vehicle_marka,
     51    v.model  AS vehicle_model,
     52    v.license_plate  AS license_plate
     53FROM
     54    CustomerPolicyInfo cpi
     55LEFT JOIN project.Pol_travel pt ON cpi.policy_id = pt.pol_id
     56LEFT JOIN project.Pol_osi po ON pt.tr_id = po.policy
     57LEFT JOIN project.Pol_auto pa ON cpi.policy_id = pa.pol_id
     58LEFT JOIN project.Vehicle v ON pa.a_id = v.policy
     59
     60
     61}}}
     62
     63=== Извештај за број на закажани полиси за одреден клиент ===
     64
     65{{{#!sql
     66
     67SELECT
     68    c.c_id,
     69    c.name AS customer_name,
     70    c.email,
     71    COUNT(p.p_id) AS reserved_policies_count
     72FROM
     73    project.Customer c
     74LEFT JOIN project.Pol_dog pd ON c.c_id = pd.c_id
     75LEFT JOIN project.Policy p ON pd.policy = p.p_id
     76GROUP BY
     77    c.c_id, c.name, c.email
     78ORDER BY
     79    reserved_policies_count DESC;
     80}}}
     81