java - How to sum data from specific record? -
___worker_id___|_______occur________ 20 | 1 20 | 2 21 | 3 22 | 5 20 | 1 according table, need know each worker how many occur? such worker_id=20 has occur 4 worker_id=21 has occur 8
i can 2 value worker table code
string sql = "select table.worker_id,table.occur keyword_pages table" + " keyword_id=" + puid; conn = getconnection(); stm = conn.createstatement(); rs = stm.executequery(sql); while (rs.next()) { int kwd_id = rs.getint(1); /**worker_id 20,20,21,22,20*/ int occur = rs.getint(2); /**worker_id 1,2,3,5,1*/ }
how amount of occur each worker?
this coding. use hashmap store each record. , store hashmap linklist. haven't idea result.
conn = getconnection(); stm = conn.createstatement(); rs = stm.executequery(sql); while (rs.next()) { int kwd_id = rs.getint(1); int occur = rs.getint(2); hmap.put(kwd_id, occur); listid.add(hmap); //system.out.println(kwd_id +" | "+ occur); } (int = 0; < listid.size(); i++) { }
string sql = "select t.worker_id, sum(t.occur) osum" + " keyword_pages t" + " keyword_id=" + puid + " group t.worker_id";
now rs.getint(2)
or rs.getint("osum")
give group's sum.
Comments
Post a Comment