database - SQL query for finding percentage of new records in a table -
i have 2 tables table1
, table2
.
each of these tables have columns column1, column2
.
i need find percentage of new column1 in table1 group column2.
1) count of new records in column1 = count of (distinct column1 present in table1 , not in table2).
2) count of distinct column1 in tableone
percentage = (1 / 2) * 100.
what tried is
select count(distinct column1) tableone left outer join tabletwo on (tableone.column1=tabletwo.column2) tabletwo.column1 null.
and this:
select count(distinct column1) tableone.
now how combine both in single query , group column2.
quick way is:
select ((counta/countb)*100) percentage ( select count(distinct column1) counta, (select count(distinct column1) tableone) countb tableone left outer join tabletwo on (tableone.column1=tabletwo.column2) tabletwo.column1 null) x x
for grouping column2, have add query. need know column2 want group it.
if need cross reference in between tables (1 & 2) it'll bit more complicated.
Comments
Post a Comment