开发者

To normalize the values

import java.io.*;
import java.sql.*;

public class Sum2{

public static void main(String[] args) {

   System.out.println("Sum of the specific column!");
   Connection con = null;

   try
   {
      Class.forName("com.mysql.jdbc.Driver");
        con=DriverManager.getConnection("jdbc:mysql://localhost:3306/prathi","root","mysql");

    try
    {
     Statement st = con.createStatement();       
     ResultSet res = st.executeQuery("SELECT  Service_ID,SUM(consumer_feedback) FROM  consumer2 group by Service_ID"); 
    while (res.next())
               { 
      int data=res.getInt(1); 
      System.out.println(data);
      System.out.println("\n\n");

      int c1 = res.getInt(2); 

      System.out.print(c1); 
      System.out.println("\n\n");        

     }  
  开发者_Go百科 }

  catch (SQLException s)
   {
    System.out.println("SQL statement is not executed!");
   }
  }


   catch (Exception e)
   {
     e.printStackTrace();
   }

  }
} 

I got the output as

C:>javac Sum4.java

C:>java Sum4 Sum of the specific column! 31

0 0

32

2 2

33

-1 0

I calculated the sum .Then I assigned negative values as zero.I need to normalize these values ie I have to find the value of 2/2. (First I will find the total and divide each value by total). I want the result to be simulated automatically for any number.Please give me some idea

Thank You ...


Is this what you mean?

SELECT Service_ID,SUM(consumer_feedback),Sum(consumer_feedback)/count(*)
 FROM consumer2
 GROUP BY Service_ID
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜