Query SQL GROUP BY

Discussion in 'C#' started by viki1967, Apr 11, 2008.

  1. #1
    Hello everyone.

    I have this problem with table of database MySQL.

    My table with fields ID, Number and Description:

    
    [b]ID ====== NUMBER ======= DESCRIPTION[/b]
    1  ====== 9168381650==== CDR VER-CS AP-UPS SANLUCA
    2  ====== 9168381659==== CDR VER-CS AP-UPS SANLUCA-9
    3  ====== 9168381651==== CDR VER-CS AP-UPS SANLUCA-SQ S.SANLUCA
    4  ====== 9168381652==== CDR VER-CS AP-UPS SANLUCA-SQ DIST.GUSPIN
    
    Code (markup):
    From this table I need to have the total of records data all under the description CDR VER AP-CS-UPS SANLUCA.

    Is a hierarchy structure where IDs 2, 3 and 4 belong to the description ID 1.

    I don't like to see the data individually for each description, but the grouping data for macro-DESCRIPTION.

    For example:

    The total records in table are 4, the query return:
    "There are 4 records total for description CDR VER AP-CS-UPS SANLUCA."

    thanks for your help, regards.
    viki
     
    viki1967, Apr 11, 2008 IP
  2. entwickler

    entwickler Member

    Messages:
    74
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    Select Count(*) From Tablename Where Description Like 'cdr Ver Ap-cs-ups Sanluca'
     
    entwickler, Apr 12, 2008 IP
  3. viki1967

    viki1967 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for your reply.

    The query is good if in the table I have only DESCRIPTION = CDR VER AP-CS-UPS SANLUCA.

    The table contains data of this type:

    ID ====== NUMBER ====== DESCRIPTION
    1 ====== 9168381650==== CDR VER-CS AP-UPS SANLUCA
    2 ====== 9168381659==== CDR VER-CS AP-UPS SANLUCA-9
    3 ====== 9168381651==== CDR VER-CS AP-UPS SANLUCA-SQ S.SANLUCA
    4 ====== 9168381652==== CDR VER-CS AP-UPS SANLUCA-SQ DIST.GUSPIN

    5 ====== 9168381653==== CDR VER-CS AP-UPS SANVITO
    6 ====== 9168381656==== CDR VER-CS AP-UPS SANVITO-9
    7 ====== 9168381658==== CDR VER-CS AP-UPS SANVITO-SQ S.SANVITO
    8 ====== 9168381655==== CDR VER-CS AP-UPS SANVITO-SQ DIST.GUSPIN

    5 ====== 9168381643==== CDR VER-CS AP-UPS SANPIO
    6 ====== 9168381646==== CDR VER-CS AP-UPS SANPIO-9
    7 ====== 9168381648==== CDR VER-CS AP-UPS SANPIO-SQ S.SANPIO
    8 ====== 9168381645==== CDR VER-CS AP-UPS SANPIO-SQ DIST.GUSPIN

    Are 5000 records groups by 4 where and DESCRIPTION and NUMBER are always different ...

    Your query is valid only for CDR VER AP-CS-UPS SANLUCA...

    The problem is that:

    Counter rows in the table for description and see only macro-description...

    CDR VER-CS AP-UPS SANLUCA ===> 4 rows
    CDR VER-CS AP-UPS SANVITO ===> 4 rows
    CDR VER-CS AP-UPS SANPIO ===> 4 rows
     
    viki1967, Apr 12, 2008 IP