tender id procedure type days to prepare total bids n files n file types mb files file types
152877
Atklāts konkurss
21
6
22
3
2.37
doc docx pdf
146863
Mazie iepirkumi
19
4
20
6
0.65
doc docx edoc id146863_mimetype pdf xlsx
153433
Atklāts konkurss
14
5
19
5
2.24
doc docx edoc id153433_mimetype pdf
153631
Mazie iepirkumi
17
3
18
2
0.81
docx pdf
144471
Mazie iepirkumi
15
2
17
4
0.8
docx edoc id144471_mimetype pdf
151019
Mazie iepirkumi
15
2
16
2
1.47
docx pdf
144555
Atklāts konkurss
16
4
16
5
0.75
doc docx edoc id144555_mimetype pdf
148738
Atklāts konkurss
29
74
15
4
3.02
docx pdf xlsx zip
144117
Atklāts konkurss
41
5
14
5
0.95
docx edoc id144117_mimetype pdf xlsx
157387
Atklāts konkurss
15
2
12
3
4.12
docx pdf xlsx
157384
Atklāts konkurss
15
4
12
3
1.77
docx pdf xlsx
151178
Mazie iepirkumi
15
1
11
2
0.43
docx pdf
153192
Mazie iepirkumi
17
1
11
3
0.52
docx pdf xlsx
155963
Atklāts konkurss
29
1
10
4
0.63
docx edoc id155963_mimetype pdf
144497
Mazie iepirkumi
22
2
10
3
1.08
doc docx pdf
156355
Atklāts konkurss
23
2
10
5
2.93
doc docx edoc id156355_mimetype pdf
154274
Mazie iepirkumi
15
2
10
3
4.25
docx pdf zip
150902
Mazie iepirkumi
21
3
10
4
1.49
docx edoc id150902_mimetype pdf
151080
Atklāts konkurss
16
1
9
5
0.45
docx edoc id151080_mimetype pdf xls
153570
Mazie iepirkumi
17
1
9
5
2.48
doc docx edoc id153570_mimetype pdf
144476
Mazie iepirkumi
15
2
9
3
0.77
docx pdf xlsx
143415
Mazie iepirkumi
15
8
9
5
0.43
doc docx edoc id143415_mimetype pdf
148991
Atklāts konkurss
30
2
8
3
1.22
doc docx pdf
153292
Atklāts konkurss
17
2
7
4
0.3
docx edoc id153292_mimetype pdf
133703
Atklāts konkurss
33
3
7
4
0.39
docx edoc id133703_mimetype pdf
156048
Atklāts konkurss
16
4
7
2
0.49
docx pdf
155433
Mazie iepirkumi
15
4
7
2
1.25
docx pdf
157474
Mazie iepirkumi
15
1
5
3
0.38
doc docx pdf
WITH docs AS (
  SELECT
    procurement_id AS tender_id,
    count(*) AS n_files,
    count(DISTINCT lower(file_type)) AS n_file_types,
    sum(try_cast(bytes AS BIGINT)) AS total_bytes,
    string_agg(DISTINCT lower(file_type), ', ' ORDER BY lower(file_type)) AS file_types
  FROM xlsx_inventory_v3_4b022d33_2
  GROUP BY procurement_id
), tenders AS (
  SELECT
    tender_id,
    procedure_type,
    try_cast(days_to_prepare AS DOUBLE) AS days_to_prepare,
    try_cast(total_bids AS DOUBLE) AS total_bids,
    try_cast(award_amount AS DOUBLE) AS award_amount
  FROM xlsx_inventory_v3_4b022d33_5
)
SELECT
  t.tender_id,
  t.procedure_type,
  t.days_to_prepare,
  t.total_bids,
  d.n_files,
  d.n_file_types,
  round(d.total_bytes / 1000000.0, 2) AS mb_files,
  d.file_types
FROM tenders t
LEFT JOIN docs d USING (tender_id)
ORDER BY d.n_files DESC NULLS LAST, t.total_bids ASC;