How to calculate percentage with a SQL statement? [closed]












1















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?










share|improve this 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.





















    1















    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?










    share|improve this 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.



















      1












      1








      1


      0






      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?










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      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.






















          1 Answer
          1






          active

          oldest

          votes


















          0














          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.






          share|improve this answer






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            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.






            share|improve this answer




























              0














              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.






              share|improve this answer


























                0












                0








                0







                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.






                share|improve this answer













                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 28 '18 at 12:05









                harrymcharrymc

                256k14268568




                256k14268568















                    Popular posts from this blog

                    Plaza Victoria

                    In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

                    How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...