most popular value in a column

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default most popular value in a column

    if I have 10 records :

    ID_______thisval__________name
    1________5______________bob
    2________3______________bill
    3________3______________diane
    4________2______________jacko
    5________2______________jean
    6________3______________gloria

    and I want to run a report on the most popular "thisval"
    is there anyway to do this in an sql query rather than using alot of CF loops
    etc...

    i basicly want the output

    val_____________countnum
    3______________3
    2______________2
    5______________1

    i tried the following but it only returned one column

    <cfquery datasource="#datsrc1#" name="getComp" maxrows="10">SELECT
    COUNT(DISTINCT thisVal) AS "countNum" FROM table WHERE thisDate >
    "#DateFormat(DateAdd("m", -6, now()), "yyyy-mm-dd")#" AND thisVal <> "" ORDER
    BY thisVal</cfquery>


    TIA =)

    glossen Guest

  2. Similar Questions and Discussions

    1. Popular video and realtime stats
      Hi, I need to get the most popular videos hosted on the FMS. How can I get that. Also I want to get at any time the stats for the viewer ship...
    2. !! DOWNLOAD THE MOST POPULAR 2006's CRACKED SOFTWARE(CAD/CAE/CAM/EDA/PCB/GIS/CNC/FEA)
      Our team provide different types of services such as: - proffessional cracking of any kind of softwar...
    3. !! DOWNLOAD THE MOST POPULAR 2006's CRACKED SOFTWARE(CAD/CAE/CAM/EDA/PCB/GIS/FEA/CNC)
      Our team provide different types of services such as: - proffessional cracking of any kind of softwar...
    4. !! DOWNLOAD THE MOST POPULAR 2005's CRACKED SOFTWARE(CAD/CAE/CAM/EDA/GIS/PCB/FEA/CNC/
      Our Team provide CRACKED engineering and technical software at thi topics: => Civil and Structural => Survey , GIS , Rock , Soil and Water =>...
    5. Ruby could be wildly more popular if it had ...
      Brackets. Huh? What do you mean "brackets"? Brackets. Ruby doesn't have enough brackets. Hmph! I think ruby has the exact right amount of...
  3. #2

    Default Re: most popular value in a column

    <cfquery datasource="#datsrc1#" name="getComp" maxrows="10">
    SELECT thisVal,
    COUNT(DISTINCT thisVal) AS "countNum"
    FROM table
    WHERE thisDate > "#DateFormat(DateAdd("m", -6, now()), "yyyy-mm-dd")#"
    AND thisVal <> ""
    GROUP BY thisVal
    ORDER BY 2 DESC
    </cfquery>

    Phil


    paross1 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139