lundi 26 octobre 2015

sql combining count with other fields

Consider a scenario:

id    name  info  done
-----------------------
1     abc    x      0
2     abc    y      1   <-- I have this id
3     pqr    g      1
4     pqr    h      0
5     pqr    i      1   <-- I have this id

I have id for the last entry of every name.

The result I'm expecting consists of 2 things:

  1. info for last entry of the name

  2. number of done [having value 1] for that name

(1) can be easily achieved by select info from table where id = myid

But how can (2) be achieved in the same query? Can it be achieved in the same query?

Something like

select info, count(done) from table where id = myid group by name where ......

Aucun commentaire:

Enregistrer un commentaire