SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Sep 2003
    Location
    Northern California
    Posts
    605
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    quick ? : mysql duplicate row data vs adding hits col.

    I've got this hypothetical table:

    id deptID subdeptID promo sku
    =======================
    001 A 123 --- 789
    002 A --- xyz 789
    003 A 123 --- 789

    I want to report a summary of the table that groups identical rows and counts them. E.g. :

    Dept subdeptID promo sku
    ========================
    A 123 --- (2)
    A 123 xyz (1)

    Would it be wiser to write a SELECT query to obtain the second table above (if it's feasible), or instead add a "hits" column that increments by '1' when a row containing data identical to an existing row is to be stored?

    TIA...

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,250
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Code:
    select Dept 
         , subdeptID 
         , promo 
         , count(*) as hits
      from hypothetical 
    group
        by Dept 
         , subdeptID 
         , promo
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Guru
    Join Date
    Sep 2003
    Location
    Northern California
    Posts
    605
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you....being just a meager web developer I did not know I could GROUP By multiple columns (or if I did, it was forgotten).


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
  •