SELECT * , COUNT( * ) FROM GROUP BY ORDER BY DESC
Posted
by
quanganh_developer
on Stack Overflow
See other posts from Stack Overflow
or by quanganh_developer
Published on 2012-11-01T04:52:05Z
Indexed on
2012/11/01
5:00 UTC
Read the original article
Hit count: 111
I have a table like:
gold
gold_city | gold_type | gold_selltime
-------------------------------------
city1 | type 1 | 2012-01-01
city1 | type 1 | 2012-02-02
city1 | type 1 | 2012-03-03
city2 | type 2 | 2012-01-01
city2 | type 2 | 2012-02-02
city2 | type 2 | 2012-03-03
city3 | type 3 | 2012-01-01
city3 | type 3 | 2012-02-02
city3 | type 3 | 2012-03-03
How can I get 1 last result order by gold_selltime
desc each group by gold_city and gold_type
I used this:
SELECT * , COUNT( * )
FROM gold_2012
GROUP BY gold_type , gold_city
ORDER BY gold_selltime DESC
but it did work. I only have result like:
gold_city | gold_type | gold_selltime
-------------------------------------
city1 | type 1 | 2012-01-01
city2 | type 2 | 2012-01-01
city3 | type 3 | 2012-01-01
but I need it like:
gold_city | gold_type | gold_selltime
-------------------------------------
city1 | type 1 | 2012-03-03
city2 | type 2 | 2012-03-03
city3 | type 3 | 2012-03-03
© Stack Overflow or respective owner