Given the fetched row below I need to also total how may id-token pair has a valuableField. The value in valuableField
may have duplicates
the field
id
- column of table
token
- column of table
valuableField
- column of table
How do I do the totalCountOfValuableFIeld
field?
totalCountOfValuableField
- not a column in a table and is the total count of distinct `valuableField per id-token pair.
I tried this query but it forces me to group the rows but that is not what I want.
select id, token, valuableField, count(distinct valuableField) from table_1
Sample Data
Current Table
╔════════╦═════════════╦═══════════════╗
║ id ║ token ║ valuableField ║
╠════════╬═════════════╬═══════════════╣
║ 88 ║ test ║ unique1 ║
║ 88 ║ test ║ duplicate1 ║
║ 88 ║ random1 ║ 1unique ║
║ 88 ║ test ║ duplicate1 ║
║ 76 ║ bar ║ 1unique ║
║ 76 ║ bar ║ 2unique ║
╚════════╩═════════════╩═══════════════╝
What I want
╔════════╦═════════════╦═══════════════╦════════════════════════════╗
║ id ║ token ║ valuableField ║ totalCountOfValuableField ║
╠════════╬═════════════╬═══════════════╬════════════════════════════╣
║ 88 ║ test ║ unique1 ║ 2 ║
║ 88 ║ test ║ duplicate1 ║ 2 ║
║ 88 ║ random1 ║ 1unique ║ 1 ║
║ 88 ║ test ║ duplicate1 ║ 2 ║
║ 76 ║ bar ║ 2unique ║ 2 ║
║ 76 ║ bar ║ 3unique ║ 2 ║
╚════════╩═════════════╩═══════════════╩════════════════════════════╝