# Calculate same values \[Problem\]

**URL:** https://forums.percona.com/t/calculate-same-values-problem/1033
**Category:** Other MySQL® Questions
**Created:** [December 11, 2008, 5:58pm UTC](https://forums.percona.com/t/calculate-same-values-problem/1033 "2008-12-11T17:58:54Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![sweb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/sweb/32/798_2.png) [@sweb](https://forums.percona.com/u/sweb)
#### Post date: [December 11, 2008, 5:58pm UTC](https://forums.percona.com/t/calculate-same-values-problem/1033/1 "2008-12-11T17:58:54Z")

</div>

i need the MySQL query for calculate the number the rows that have a same value in a one or more cells:  
See my example:

-----------------------------------------# | user\_ip | user\_useragent | user\_lang-----------------------------------------1 | 55.12.15 | Firefox | en2 | 55.12.11 | Firefox | en3 | 55.12.15 | IE | en4 | 55.12.15 | Opera | en5 | 55.12.15 | Firefox | de6 | 55.12.15 | IE | en7 | 55.12.81 | Firefox | en-----------------------------------------

Request : That calculate number of rows that have a same value in the `user_lang` and `user_useragent`:  
The rows 1, 2, 7 have same value in `user_lang` and `user_useragent`. \>\> 3 row  
Also the rows 3 and 6 have same value in `user_lang` and `user_useragent`. \>\> 2 row  
The result must be 5.  
Did you understand? I want the SQL comment to process for getting number 5.

I can use the array\_unique in PHP for calculate but i want process it with MySQL functions.  
thanks and be waiting.

---

<div class="post-metadata">

### Author: ![januzi](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@januzi](https://forums.percona.com/u/januzi)
#### Post date: [December 11, 2008, 6:13pm UTC](https://forums.percona.com/t/calculate-same-values-problem/1033/2 "2008-12-11T18:13:33Z")

</div>

edit:

select sum(amount) from (  
select user\_agent, user\_lang, count(\*) as amount from table group by concat( user\_agent, user\_lang)  
) as t1 where amount \> 1

---

<div class="post-metadata">

### Author: ![sweb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/sweb/32/798_2.png) [@sweb](https://forums.percona.com/u/sweb)
#### Post date: [December 11, 2008, 6:23pm UTC](https://forums.percona.com/t/calculate-same-values-problem/1033/3 "2008-12-11T18:23:10Z")

</div>

thank for your quick replying.  
it’s complicate.  
please show the some tutorial link to lean the complicate sql query. 😃

---

<div class="post-metadata">

### Author: ![januzi](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@januzi](https://forums.percona.com/u/januzi)
#### Post date: [December 11, 2008, 6:30pm UTC](https://forums.percona.com/t/calculate-same-values-problem/1033/4 "2008-12-11T18:30:42Z")

</div>

[URL=“http&#58;&#47;&#47;[www.xaprb.com/blog/](http://www.xaprb.com/blog/)”][http://www.xaprb.com/blog/[/URL]](http://www.xaprb.com/blog/%5B/URL%5D)  
[URL=“http&#58;&#47;&#47;[www.mysqlperformanceblog.com/](http://www.mysqlperformanceblog.com/)”][http://www.mysqlperformanceblog.com/[/URL]](http://www.mysqlperformanceblog.com/%5B/URL%5D)

Those two guys are the best. I looked for other sources of knowledge, but I couldn’t find anything interesting.

You could also google: mysql subquery, mysql subqueries. You should find syntax etc.

---

<div class="post-metadata">

### Author: ![sweb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/sweb/32/798_2.png) [@sweb](https://forums.percona.com/u/sweb)
#### Post date: [January 21, 2009, 4:26pm UTC](https://forums.percona.com/t/calculate-same-values-problem/1033/5 "2009-01-21T16:26:07Z")

</div>

i have this data:

user\_agent | user\_lang==========================Firefox | enIE | enIE | enFirefox | fi

and excute this values for my question:

select sum(amount) from (select user\_agent, user\_lang, count(\*) as amount from table group by concat( user\_agent, user\_lang)) as t1 where amount \> 1

returned value is 2 that i want to be 3.  
we have 3 rows that have different value in user\_agent and user\_lang.  
thank and be waiting for answer.

---

<div class="post-metadata">

### Author: ![januzi](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@januzi](https://forums.percona.com/u/januzi)
#### Post date: [January 21, 2009, 5:58pm UTC](https://forums.percona.com/t/calculate-same-values-problem/1033/6 "2009-01-21T17:58:12Z")

</div>

In that case remove “where amount \> 1”  
You will get all records, even if there was only one visitor with that browser and language

---

<div class="post-metadata">

### Author: ![sweb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/sweb/32/798_2.png) [@sweb](https://forums.percona.com/u/sweb)
#### Post date: [January 21, 2009, 10:44pm UTC](https://forums.percona.com/t/calculate-same-values-problem/1033/7 "2009-01-21T22:44:16Z")

</div>

i execute this query:

select sum(amount) from (select user\_agent, user\_lang, count(\*) as amount from table group by concat( user\_agent, user\_lang)) as t1

the result is 4. i want to have result 3. (

---

<div class="post-metadata">

### Author: ![januzi](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@januzi](https://forums.percona.com/u/januzi)
#### Post date: [January 22, 2009, 4:16am UTC](https://forums.percona.com/t/calculate-same-values-problem/1033/8 "2009-01-22T04:16:41Z")

</div>

| [B]Quote:[/B] |
| 

select count(\*) as amount from (  
select user\_agent, user\_lang from table group by concat( user\_agent, user\_lang)  
) as t1

 |

How 'bout this ?
