开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 2063|回复: 2
收起左侧

[Mysql] MySQL (非存储过程)解决易语言难题

[复制链接]

结帖率:33% (1/3)
发表于 2013-2-21 13:00:15 | 显示全部楼层 |阅读模式   上海市上海市
很多人用不同的东西来解决易语言难题,咱也凑个热闹。如果用存储过程的话,和一般的编程语言也就雷同了,这里就用SQL的思想,在MySQL中实现一次。
  1. drop table if exists n1;
  2. create temporary table n1(num int (1));
  3. insert into n1 values(1), (2), (3), (4), (5), (6), (7), (8), (9);

  4. drop table if exists n2;
  5. create temporary table n2
  6. select * from n1;

  7. drop table if exists n3;
  8. create temporary table n3
  9. select * from n1;

  10. drop table if exists nums1;
  11. create temporary table nums1
  12. select n1.num * 100 + n2.num * 10 + n3.num as num
  13. from n1 left join n2
  14. on n1.num <> n2.num
  15. left join n3
  16. on n1.num <> n3.num and n2.num <> n3.num;

  17. drop table if exists nums2;
  18. create temporary table nums2
  19. select * from nums1;

  20. drop table if exists nums3;
  21. create temporary table nums3
  22. select * from nums1;

  23. select *
  24. from nums1 as n1 left join nums2 as n2
  25. on n1.num <> n2.num
  26. left join nums3 as n3
  27. on n1.num <> n3.num and n2.num <> n3.num
  28. where n1.num * 2 = n2.num and n1.num * 3 = n3.num
  29. and n1.num not rlike concat("[", n2.num, "]")
  30. and n1.num not rlike concat("[", n3.num, "]")
  31. and n2.num not rlike concat("[", n3.num, "]");

  32. drop table if exists n1;
  33. drop table if exists n2;
  34. drop table if exists n3;
  35. drop table if exists nums1;
  36. drop table if exists nums2;
  37. drop table if exists nums3;


  38. 结果:
  39. mysql> select *
  40.     -> from nums1 as n1 left join nums2 as n2
  41.     -> on n1.num <> n2.num
  42.     -> left join nums3 as n3
  43.     -> on n1.num <> n3.num and n2.num <> n3.num
  44.     -> where n1.num * 2 = n2.num and n1.num * 3 = n3.num
  45.     -> and n1.num not rlike concat("[", n2.num, "]")
  46.     -> and n1.num not rlike concat("[", n3.num, "]")
  47.     -> and n2.num not rlike concat("[", n3.num, "]");
  48. +------+------+------+
  49. | num  | num  | num  |
  50. +------+------+------+
  51. |  192 |  384 |  576 |
  52. |  219 |  438 |  657 |
  53. |  273 |  546 |  819 |
  54. |  327 |  654 |  981 |
  55. +------+------+------+
  56. 4 rows in set (0.03 sec)
复制代码
结帖率:100% (2/2)
发表于 2022-9-17 11:05:14 | 显示全部楼层   江西省南昌市
意义大吗
回复 支持 反对

使用道具 举报

结帖率:37% (7/19)
发表于 2013-3-1 15:35:19 | 显示全部楼层   北京市北京市
沙发            
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 793400750,邮箱:wp@125.la
网站简介:精易论坛成立于2009年,是一个程序设计学习交流技术论坛,隶属于揭阳市揭东区精易科技有限公司所有。
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表