Results 1 to 4 of 4

Thread: Creating new table from existing table

  1. #1
    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?

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    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;

  3. #3
    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.

  4. #4
    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.



    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.

Similar Threads

  1. Replies: 2
    Last Post: 16-02-2012, 06:28 PM
  2. Replies: 5
    Last Post: 27-08-2011, 10:53 AM
  3. Link a Table to another Table to Drop Down In Main Table
    By himeshRES in forum Windows Software
    Replies: 6
    Last Post: 11-12-2010, 02:01 PM
  4. Replies: 4
    Last Post: 30-11-2010, 03:01 AM
  5. Creating a Hash Table in java
    By Sheenas in forum Software Development
    Replies: 5
    Last Post: 19-02-2010, 07:24 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,049,025.74721 seconds with 16 queries