0

I have such query

SELECT `id`
FROM (`TABLE`)
WHERE date(FROM_UNIXTIME(time)) >= '2013-10-28'
GROUP BY `last`
ORDER BY `id_s` DESC

the result is:

| id |

9
1
1
9
50
3
1

My question is how to count how many times repeating number 9 in result?

So, the final result must be one row with number 2

Somebody have idea how possible to do it?

1
  • Please provide information about the table structure and some example data. Commented Oct 29, 2014 at 10:22

2 Answers 2

1

You could just use the result set that you already have, select id=9 from it and count the rows:

SELECT COUNT(*)
FROM (
  --your current query here
) WHERE `id`=9
GROUP BY `id`

There might be a better way of doing this in your situation, but without knowing your table structure and maybe seeing some example data, this is hard to tell.

Sign up to request clarification or add additional context in comments.

Comments

1

You would use count(*):

SELECT count(distinct last)
FROM (TABLE)
WHERE date(FROM_UNIXTIME(time)) >= '2013-10-28' AND
      id = 9 ;

I'm not sure what the group by really does, so it might be sufficient to do:

SELECT count(*)
FROM (TABLE)
WHERE date(FROM_UNIXTIME(time)) >= '2013-10-28' AND
      id = 9 ;

3 Comments

Unfortunatly will not work becouse key in this query is "ORDER BY id_s"
The best way will if is possible to get this 9 after executed this query?
I am totally missing something. The order by has nothing to do with how many times the value "9" appears.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.