Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 29-10-2009
Member
 
Join Date: Aug 2009
Posts: 56
Creating new table from existing table

I get a list of city from a database in a table.

My table:

Kolkata
Kolkata
Kolkata
Mumbai
Mumbai
Bengaluru
...

I would like from this table to create another table like this

Kolkata 3
Mumbai 2
Bengaluru 1

How do I do that?
Reply With Quote
  #2  
Old 29-10-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: Creating new table from existing table

Why not do this in your DBMS with a simple query, its more practical and you have a table of two dimensions.
Code:
 select Distinct (name) ,count (name) from test group by name;
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #3  
Old 29-10-2009
Member
 
Join Date: Aug 2009
Posts: 56
Re: Creating new table from existing table

Yes to consolidate the cities I tried LinkedHashMap putting in key cities, it works, but I can not count with this method the number of Occurrence of each city.

How can I do?
Code:
select Distinct (name) ,count (name) from test group by name;
I did not direct my table with my city is already extracted.
Reply With Quote
  #4  
Old 29-10-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: Creating new table from existing table

The interface Bag of commons-collections, for example implemented by HashBag kit, is precisely that.



Quote:
Syntax

public class HashBag
extends AbstractMapBag
implements Bag, java.io.Serializable

Description

Implements Bag, using a HashMap to provide the data storage. This is the standard implementation of a bag.

A Bag stores each object in the collection together with a count of occurrences. Extra methods on the interface allow multiple copies of an object to be added or removed at once. It is important to read the interface javadoc carefully as several methods violate the Collection interface specification.
If you can not use any external library like commons-collections, you have more than one redo HashBag kit. Basically it's like HashMap, except that the value associated with key is the number of times this key has been added to the Map.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Creating new table from existing table"
Thread Thread Starter Forum Replies Last Post
How to add a result column in Pivot table by subtracting two existing columns in Excel Irritator MS Office Support 2 16-02-2012 06:28 PM
Unable to work with table columns in opera browser when the table has wide layout Janya Technology & Internet 5 27-08-2011 10:53 AM
Link a Table to another Table to Drop Down In Main Table himeshRES Windows Software 6 11-12-2010 02:01 PM
Colonizing a table of employees from a table of applicants in Microsoft Access laplapye Windows Software 4 30-11-2010 03:01 AM
Creating a Hash Table in java Sheenas Software Development 5 19-02-2010 07:24 PM


All times are GMT +5.5. The time now is 01:53 AM.