How to calculate percentage with a SQL statement? [closed]
i have two sql tables i want to compare two tables ..comparing two tables is done now what i want is how many records are matched and not matched in the form of percentage .is it possible to write a query in sql to get percentage?
and here is my tables
src_table
----------------------------------------------------------------
src_table
----------------------------------------------------------------
1
2
3
a
b
c
a@
b@
c@
-----------------------------------------------------------------
and tgt_table is
-----------------------------------------------------------------
tgt_data
-----------------------------------------------------------------
1
4
5
a
e
f
a@
e@
f@
--------------------------------------------------------------------
and now i want matched data and unmatched in the form of percentage is it possible?
sql-server sql
closed as off-topic by fixer1234, Twisty Impersonator, PeterH, avirk, LotPings Jan 3 at 20:23
- This question does not appear to be about computer software or computer hardware within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
i have two sql tables i want to compare two tables ..comparing two tables is done now what i want is how many records are matched and not matched in the form of percentage .is it possible to write a query in sql to get percentage?
and here is my tables
src_table
----------------------------------------------------------------
src_table
----------------------------------------------------------------
1
2
3
a
b
c
a@
b@
c@
-----------------------------------------------------------------
and tgt_table is
-----------------------------------------------------------------
tgt_data
-----------------------------------------------------------------
1
4
5
a
e
f
a@
e@
f@
--------------------------------------------------------------------
and now i want matched data and unmatched in the form of percentage is it possible?
sql-server sql
closed as off-topic by fixer1234, Twisty Impersonator, PeterH, avirk, LotPings Jan 3 at 20:23
- This question does not appear to be about computer software or computer hardware within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
i have two sql tables i want to compare two tables ..comparing two tables is done now what i want is how many records are matched and not matched in the form of percentage .is it possible to write a query in sql to get percentage?
and here is my tables
src_table
----------------------------------------------------------------
src_table
----------------------------------------------------------------
1
2
3
a
b
c
a@
b@
c@
-----------------------------------------------------------------
and tgt_table is
-----------------------------------------------------------------
tgt_data
-----------------------------------------------------------------
1
4
5
a
e
f
a@
e@
f@
--------------------------------------------------------------------
and now i want matched data and unmatched in the form of percentage is it possible?
sql-server sql
i have two sql tables i want to compare two tables ..comparing two tables is done now what i want is how many records are matched and not matched in the form of percentage .is it possible to write a query in sql to get percentage?
and here is my tables
src_table
----------------------------------------------------------------
src_table
----------------------------------------------------------------
1
2
3
a
b
c
a@
b@
c@
-----------------------------------------------------------------
and tgt_table is
-----------------------------------------------------------------
tgt_data
-----------------------------------------------------------------
1
4
5
a
e
f
a@
e@
f@
--------------------------------------------------------------------
and now i want matched data and unmatched in the form of percentage is it possible?
sql-server sql
sql-server sql
asked Dec 28 '18 at 11:43
dumbuudumbuu
404
404
closed as off-topic by fixer1234, Twisty Impersonator, PeterH, avirk, LotPings Jan 3 at 20:23
- This question does not appear to be about computer software or computer hardware within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.
closed as off-topic by fixer1234, Twisty Impersonator, PeterH, avirk, LotPings Jan 3 at 20:23
- This question does not appear to be about computer software or computer hardware within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I assume you wish to calculate the percentage over the table tgt_data
.
If this is not the case, just exchange the table names below.
The query depends on the capabilities of your SQL product.
If it cannot handle complex expressions with sub-queries, you will need
to break the expression into multiple statements.
The expression you would like to calculate is:
(select count(*) * 100 from tgt_data t where exists
(select * from src_table where src_col = t.tgt_col))
/
(select count(*) from tgt_data)
If you need to formulate it as one SELECT statement, this is an alternate formulation:
select
(select count(*) * 100 from tgt_data t where exists
(select * from src_table where src_col = t.tgt_col))
/ count(*)
from tgt_data
If your product calculates this in integer arithmetic, and you would like
the result in decimal, then replace 100
by 100.0
above.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I assume you wish to calculate the percentage over the table tgt_data
.
If this is not the case, just exchange the table names below.
The query depends on the capabilities of your SQL product.
If it cannot handle complex expressions with sub-queries, you will need
to break the expression into multiple statements.
The expression you would like to calculate is:
(select count(*) * 100 from tgt_data t where exists
(select * from src_table where src_col = t.tgt_col))
/
(select count(*) from tgt_data)
If you need to formulate it as one SELECT statement, this is an alternate formulation:
select
(select count(*) * 100 from tgt_data t where exists
(select * from src_table where src_col = t.tgt_col))
/ count(*)
from tgt_data
If your product calculates this in integer arithmetic, and you would like
the result in decimal, then replace 100
by 100.0
above.
add a comment |
I assume you wish to calculate the percentage over the table tgt_data
.
If this is not the case, just exchange the table names below.
The query depends on the capabilities of your SQL product.
If it cannot handle complex expressions with sub-queries, you will need
to break the expression into multiple statements.
The expression you would like to calculate is:
(select count(*) * 100 from tgt_data t where exists
(select * from src_table where src_col = t.tgt_col))
/
(select count(*) from tgt_data)
If you need to formulate it as one SELECT statement, this is an alternate formulation:
select
(select count(*) * 100 from tgt_data t where exists
(select * from src_table where src_col = t.tgt_col))
/ count(*)
from tgt_data
If your product calculates this in integer arithmetic, and you would like
the result in decimal, then replace 100
by 100.0
above.
add a comment |
I assume you wish to calculate the percentage over the table tgt_data
.
If this is not the case, just exchange the table names below.
The query depends on the capabilities of your SQL product.
If it cannot handle complex expressions with sub-queries, you will need
to break the expression into multiple statements.
The expression you would like to calculate is:
(select count(*) * 100 from tgt_data t where exists
(select * from src_table where src_col = t.tgt_col))
/
(select count(*) from tgt_data)
If you need to formulate it as one SELECT statement, this is an alternate formulation:
select
(select count(*) * 100 from tgt_data t where exists
(select * from src_table where src_col = t.tgt_col))
/ count(*)
from tgt_data
If your product calculates this in integer arithmetic, and you would like
the result in decimal, then replace 100
by 100.0
above.
I assume you wish to calculate the percentage over the table tgt_data
.
If this is not the case, just exchange the table names below.
The query depends on the capabilities of your SQL product.
If it cannot handle complex expressions with sub-queries, you will need
to break the expression into multiple statements.
The expression you would like to calculate is:
(select count(*) * 100 from tgt_data t where exists
(select * from src_table where src_col = t.tgt_col))
/
(select count(*) from tgt_data)
If you need to formulate it as one SELECT statement, this is an alternate formulation:
select
(select count(*) * 100 from tgt_data t where exists
(select * from src_table where src_col = t.tgt_col))
/ count(*)
from tgt_data
If your product calculates this in integer arithmetic, and you would like
the result in decimal, then replace 100
by 100.0
above.
answered Dec 28 '18 at 12:05
harrymcharrymc
256k14268568
256k14268568
add a comment |
add a comment |