query for twin primes

query for twin primes

am 13.07.2011 20:26:02 von Elim Qiu

I have a prime table
+-----+------+---------+
| oid | pv | descipt |
+-----+------+---------+
| 1 | 2 | NULL |
| 2 | 3 | NULL |
| 3 | 5 | NULL |
| 4 | 7 | NULL |
| 5 | 11 | NULL |
| ..................... |
+-----+------+---------+

what the query will be if i like to find all rows where pv+2's are
also in colum 'pv', where oid < 1000000?

In other words, how to get the list of yonger brother of the twin
primes within certain bound?

Thanks

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org

Re: query for twin primes

am 13.07.2011 20:38:30 von Shawn Wilson

--0016e649895813a28804a7f7b995
Content-Type: text/plain; charset=ISO-8859-1

On Jul 13, 2011 2:26 PM, "Elim Qiu" wrote:
>
> I have a prime table
> +-----+------+---------+
> | oid | pv | descipt |
> +-----+------+---------+
> | 1 | 2 | NULL |
> | 2 | 3 | NULL |
> | 3 | 5 | NULL |
> | 4 | 7 | NULL |
> | 5 | 11 | NULL |
> | ..................... |
> +-----+------+---------+
>
> what the query will be if i like to find all rows where pv+2's are
> also in colum 'pv', where oid < 1000000?
>

.... where ('pv' *2) = pv and old < 1000000

Untested (might be issues with my string vs number)

> In other words, how to get the list of yonger brother of the twin
> primes within certain bound?
>

--0016e649895813a28804a7f7b995--

Re: query for twin primes

am 13.07.2011 20:44:47 von mos

At 01:26 PM 7/13/2011, you wrote:
>I have a prime table
>+-----+------+---------+
>| oid | pv | descipt |
>+-----+------+---------+
>| 1 | 2 | NULL |
>| 2 | 3 | NULL |
>| 3 | 5 | NULL |
>| 4 | 7 | NULL |
>| 5 | 11 | NULL |
>| ..................... |
>+-----+------+---------+
>
>what the query will be if i like to find all rows where pv+2's are
>also in colum 'pv', where oid < 1000000?
>
>In other words, how to get the list of yonger brother of the twin
>primes within certain bound?
>
>Thanks


How about:

select t1.pv, t2.pv from prime t1, prime t2 where t2.pv=t1.pv+2 and
t1.oid<1000000 order by t2.pv

Mike


>--
>MySQL General Mailing List
>For list archives: http://lists.mysql.com/mysql
>To unsubscribe: http://lists.mysql.com/mysql?unsub=mos99@fastmail.fm


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org

Re: query for twin primes

am 13.07.2011 21:26:26 von Elim Qiu

> How about:
>
> select =A0t1.pv, t2.pv from prime t1, prime t2 where t2.pv=3Dt1.pv+2 and
> t1.oid<1000000 order by t2.pv
>
> Mike

Very nice and simple. Thanks Mike!

Also Thanks Singer X.J. Wang and shawn wilson.

best regards,
Elim

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dgcdmg-mysql-2@m.gmane.o rg

Re: query for twin primes

am 14.07.2011 10:07:02 von Simcha

On Wed, 13 Jul 2011 12:26:02 -0600
Elim Qiu wrote:

> I have a prime table
>
> what the query will be if i like to find all rows where pv+2's are
> also in colum 'pv', where oid < 1000000?
>
> In other words, how to get the list of yonger brother of the twin
> primes within certain bound?
>

select prime.* from prime join prime as p2 on prime.pv+2=p2.pv where prime.oid < 1000000;

--
Simcha Younger

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org