MySQL (non-Stored Procedure) solves easy language problems

Source: Internet
Author: User
Many people use different things to solve difficulties in easy language. If a stored procedure is used, it is similar to a general programming language. Here we use the SQL idea to implement it once in MySQL. MySQLdroptableifexistsn1; createtemporarytablen1 (numint (1); insertinton1values (1), (2), (3)

Many people use different things to solve difficulties in easy language. If a stored procedure is used, it is similar to a general programming language. Here we use the SQL idea to implement it once in MySQL. MySQL drop table if exists n1; create temporary table n1 (num int (1); insert into n1 values (1), (2), (3)

Many people use different things to solve difficulties in easy language. If a stored procedure is used, it is similar to a general programming language. Here we use the SQL idea to implement it once in MySQL.
MySQL
Drop table if exists n1; create temporary table n1 (num int (1); insert into n1 values (1), (2), (3), (4 ), (5), (6), (7), (8), (9); drop table if exists n2; create temporary table n2select * from n1; drop table if exists; create temporary table n3select * from n1; drop table if exists nums1; create temporary table nums1select n1.num * 100 + n2.num * 10 + n3.num as numfrom n1 left join n2on n1.num <> n2.numleft join n3on n1.num <> n3.num and n2.num <> n3.num; drop table if exists nums2; create temporary table nums2select * from nums1; drop table if exists nums3; create temporary table nums3select * from nums1; select * from nums1 as n1 left join nums2 as n2on n1.num <> n2.numleft join nums3 as n3on n1.num <> n3.num and n2.num <> n3.numwhere n1.num * 2 = n2.num and n1.num * 3 = Limit n1.num not rlike concat ("[", n2.num, "]") and n1.num not rlike concat ("[", n3.num, "]") and n2.num not rlike concat ("[", n3.num, "]"); drop table if exists n1; drop table if exists n2; drop table if exists n3; drop table if exists nums1; drop table if exists nums2; drop table if exists nums3; Result: mysql> select *-> from nums1 as n1 left join nums2 as n2-> on n1.num <> n2.num-> left join nums3 as n3-> on n1.num <> n3.num and n2.num <> n3.num-> where n1.num * 2 = n2.num and n1.num * 3 = n3.num-> and n1.num not rlike concat ("[", n2.num, "]")-> and n1.num not rlike concat ("[", n3.num, "]")-> and n2.num not rlike concat ("[", n3.num, "]"); + ------ + | num | + ------ + | 192 | 384 | 576 | 219 | 438 | 657 | 273 | 546 | 819 | 327 | 654 | 981 | + ------ + 4 rows in set (0.03 sec)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.