Visualizzazione dei risultati da 1 a 2 su 2

Discussione: query DISTINCT e COUNT

  1. #1
    Utente di HTML.it
    Registrato dal
    Nov 2006
    Messaggi
    656

    query DISTINCT e COUNT

    ragazzi,

    devo fare una quey che seleziona ip e data dalla tabella ma nel caso ci fossero piu record con stessa data e ip, ne deve estrrare solo 1 per quella data e ip.

    quindi faccio

    select distinct. cosi va bene no??

    poi pero devo sapere quanti record sono presenti che rispondono alla query.

    faccio cosi ma ovviamente non va bene

    SELECT DISTINCT COUNT(*) AS `nrecords` AS ip, data FROM click WHERE a =....

    come posso fare?

  2. #2
    When you're using count(), sum(), avg() with another field like data or ip you have to group your fields.

    Something like that:

    SELECT COUNT(*) as nrecords, ip, data FROM click WHERE a = XYZ GROUP BY data, ip;


    Therefore you don't need to distinct your fields


    I hope i understand your problems right.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.