I have a table like this:
jobid, orderid
And with some data inside:
jobid, orderid
1245, 6767
1235, 9058
6783, 6767
4991, 6767
9512, 9058
5123, 1234
Now I want the following output:
jobid, orderid, orderid(total)
1245, 6767, 3
1235, 9058, 2
6783, 6767, 3
4991, 6767, 3
9512, 9058, 2
5123, 1234, 1
Now, the COUNT() doesn’t work the way I want to, and I probably need some group by but I don’t know how.
Thanks in advance.
Why are doing it this way? You will be doing a lot of redundant countings and put a lot of unnecessary pressure on your server. I would do this with two queries:
to get the complete list, and then:
to get the total count for each orderid. Then combine these two results in your application. This will be much faster than your solution.