Skip to content

Commit

Permalink
Correct nopar calculation (#178)
Browse files Browse the repository at this point in the history
* Correct nopar calculation

* Address conflict between bad_doc_no and same_price_earlier_date

---------

Co-authored-by: sweatyhandshake <wridgeway@cookcountyassessor.com>
  • Loading branch information
wrridgeway and sweatyhandshake authored Oct 23, 2023
1 parent 42f7286 commit 146882e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions aws-athena/views/default-vw_pin_sale.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ calculated AS (
SELECT
instruno,
COUNT(*) AS nopar_calculated
FROM {{ source('iasworld', 'sales') }}
WHERE deactivat IS NULL
AND cur = 'Y'
FROM (
SELECT DISTINCT
parid,
instruno
FROM {{ source('iasworld', 'sales') }}
WHERE deactivat IS NULL
AND cur = 'Y'
)
GROUP BY instruno
),

Expand Down Expand Up @@ -71,12 +76,14 @@ unique_sales AS (
-- We remove the letter 'D' that trails some document numbers in
-- iasworld.sales since it prevents us from joining to mydec sales.
-- This creates one instance where we have duplicate document
-- numbers, so we sort by the original document number within the
-- numbers, so we sort by sale date (specifically to avoid conflicts
-- with detecting the easliest duplicate sale when there are
-- multiple within one document number, within a year) within the
-- new doument number to identify and remove the sale causing the
-- duplicate document number.
ROW_NUMBER() OVER (
PARTITION BY NULLIF(REPLACE(sales.instruno, 'D', ''), '')
ORDER BY sales.instruno
ORDER BY sales.saledt
) AS bad_doc_no,
-- Some pins sell for the exact same price a few months after
-- they're sold. These sales are unecessary for modeling and may be
Expand Down

0 comments on commit 146882e

Please sign in to comment.