Created
August 20, 2025 14:17
-
-
Save bryanwillis/8dc9861b5145e0b2932520dcc8e5d552 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| count(*) over(PARTITION BY d."Agent_Name" ) as count_of_rows, | |
| IFNULL(d."Override_Agent_Commission", 0) as Override_Agent_Commission_Final, | |
| IFNULL(d.Agent_Commission, 0) as Agent_Commission_Final, | |
| d.* | |
| FROM ( SELECT | |
| row_number() over() as row_number, | |
| a."Name" as Agent_Name, | |
| a."ID", | |
| a."Override Rate" as Sub_Subrate, | |
| a."Commission Rate" as Agent_Com_Rate, | |
| round(c."Total Commission" * a."Commission Rate" / 100, 2) as Agent_Commission, | |
| null as Override_Agent_Commission, | |
| c.* | |
| FROM "TelarusSync" c | |
| LEFT JOIN "BMW Agent Com Rates" a ON lower(a."ID") = lower(c."Partner Order ID") | |
| UNION | |
| SELECT | |
| row_number() over() as row_number, | |
| a."Override Partner" as Agent_Name, | |
| a."ID", | |
| a."Override Rate" as Sub_Subrate, | |
| a."Commission Rate" as Agent_Com_Rate, | |
| null as Agent_Commission, | |
| round(c."Total Commission" * a."Override Rate" / 100, 2) as Override_Agent_Commission, | |
| c.* | |
| FROM "TelarusSync" c | |
| LEFT JOIN "BMW Agent Com Rates" a ON lower(a."ID") = lower(c."Partner Order ID") | |
| ) d | |
| ORDER BY d."Agent_Name" ASC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment