ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
12
返回列表 发新帖
楼主: samichang

[求助] 非常复杂的查询,请高手进来帮忙!感谢!

[复制链接]

TA的精华主题

TA的得分主题

发表于 2009-7-17 08:37 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
对VBA来说呢记录多了也会存在慢的问题,如果只对于一行数据的话,就简单的多了

db2srrr.rar

22.67 KB, 下载次数: 9

TA的精华主题

TA的得分主题

发表于 2009-7-17 13:11 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
N1两个参数用逗号分开,
N2、N5两个参数用分号分开,
N3、N4、N6 为一个参数,
找出各参数首、尾4位数值并且唯一的查询结果
select * from
(
select iif(isnumeric(left(N1,4)),left(N1,4),null)  as N from 表1
union
select iif(isnumeric(right(left(N1,instr(N1,",")-1),4)),right(left(N1,instr(N1,",")-1),4),null) from 表1
union
select iif(isnumeric(left(right(N1,len(N1)-instr(N1,",")),4)),left(right(N1,len(N1)-instr(N1,",")),4),null) from 表1
union
select iif(isnumeric(right(right(N1,len(N1)-instr(N1,",")),4)),right(right(N1,len(N1)-instr(N1,",")),4),null) from 表1
union
select iif(isnumeric(left(N2,4)),left(N2,4),null) from 表1
union
select iif(isnumeric(right(left(N2,instr(N2,";")-1),4)),right(left(N2,instr(N2,";")-1),4),null) from 表1
union
select iif(isnumeric(left(right(N2,len(N2)-instr(N2,";")),4)),left(right(N2,len(N2)-instr(N2,";")),4),null) from 表1
union
select iif(isnumeric(right(right(N2,len(N2)-instr(N2,";")),4)),right(right(N2,len(N2)-instr(N2,";")),4),null) from 表1
union
select iif(isnumeric(left(N3,4)),left(N3,4),null) from 表1
union
select iif(isnumeric(right(N3,4)),right(N3,4),null) from 表1
union
select iif(isnumeric(left(N4,4)),left(N4,4),null) from 表1
union
select iif(isnumeric(right(N4,4)),right(N3,4),null) from 表1
union
select iif(isnumeric(left(N5,4)),left(N5,4),null) from 表1
union
select iif(isnumeric(right(left(N5,instr(N5,";")-1),4)),right(left(N5,instr(N5,";")-1),4),null) from 表1
union
select iif(isnumeric(left(right(N5,len(N5)-instr(N5,";")),4)),left(right(N5,len(N5)-instr(N5,";")),4),null) from 表1
union
select iif(isnumeric(right(right(N5,len(N5)-instr(N5,";")),4)),right(right(N5,len(N5)-instr(N5,";")),4),null) from 表1
union
select iif(isnumeric(left(N6,4)),left(N6,4),null) from 表1
union
select iif(isnumeric(right(N6,4)),right(N3,4),null) from 表1
)
where N<>null

db2.rar

17.8 KB, 下载次数: 8

TA的精华主题

TA的得分主题

发表于 2009-7-17 13:16 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
简化代码:
select * from
(
select left(N1,4)  as N from 表1
union
select right(left(N1,instr(N1,",")-1),4) from 表1
union
select left(right(N1,len(N1)-instr(N1,",")),4) from 表1
union
select right(right(N1,len(N1)-instr(N1,",")),4) from 表1
union
select left(N2,4) from 表1
union
select right(left(N2,instr(N2,";")-1),4) from 表1
union
select left(right(N2,len(N2)-instr(N2,";")),4) from 表1
union
select right(right(N2,len(N2)-instr(N2,";")),4) from 表1
union
select left(N3,4)from 表1
union
select right(N3,4) from 表1
union
select left(N4,4)from 表1
union
select right(N4,4) from 表1
union
select left(N5,4) from 表1
union
select right(left(N5,instr(N5,";")-1),4) from 表1
union
select left(right(N5,len(N5)-instr(N5,";")),4) from 表1
union
select right(right(N5,len(N5)-instr(N5,";")),4) from 表1
union
select left(N6,4) from 表1
union
select right(N6,4) from 表1
)
where N<>null and isnumeric(N)

[ 本帖最后由 Scarlett_88 于 2009-7-17 13:25 编辑 ]

TA的精华主题

TA的得分主题

 楼主| 发表于 2009-7-17 13:24 | 显示全部楼层
Renco,Scarlett
感谢你们的热心相助,让我克服了这个难题,谢谢~~

TA的精华主题

TA的得分主题

发表于 2009-7-17 13:28 | 显示全部楼层
不超过两个参数的情况通用语句:
select * from
(
select left(N1,4)  as N from 表1
union
select iif(instr(N1,";")>0,right(left(N1,instr(N1,";")-1),4),iif(instr(N1,",")>0,right(left(N1,instr(N1,",")-1),4),null)) from 表1
union
select iif(instr(N1,";")>0,left(right(N1,len(N1)-instr(N1,";")),4),iif(instr(N1,",")>0,left(right(N1,len(N1)-instr(N1,",")),4),null)) from 表1
union
select right(N1,4) from 表1
union
select left(N2,4) from 表1
union
select iif(instr(N2,";")>0,right(left(N2,instr(N2,";")-1),4),iif(instr(N2,",")>0,right(left(N2,instr(N2,",")-1),4),null)) from 表1
union
select iif(instr(N2,";")>0,left(right(N2,len(N2)-instr(N2,";")),4),iif(instr(N2,",")>0,left(right(N2,len(N2)-instr(N2,",")),4),null)) from 表1
union
select right(N2,4) from 表1
union
select left(N3,4) from 表1
union
select iif(instr(N3,";")>0,right(left(N3,instr(N3,";")-1),4),iif(instr(N3,",")>0,right(left(N3,instr(N3,",")-1),4),null)) from 表1
union
select iif(instr(N3,";")>0,left(right(N3,len(N3)-instr(N3,";")),4),iif(instr(N3,",")>0,left(right(N3,len(N3)-instr(N3,",")),4),null)) from 表1
union
select right(N3,4) from 表1
union
select left(N4,4) from 表1
union
select iif(instr(N4,";")>0,right(left(N4,instr(N4,";")-1),4),iif(instr(N4,",")>0,right(left(N4,instr(N4,",")-1),4),null)) from 表1
union
select iif(instr(N4,";")>0,left(right(N4,len(N4)-instr(N4,";")),4),iif(instr(N4,",")>0,left(right(N4,len(N4)-instr(N4,",")),4),null)) from 表1
union
select right(N4,4) from 表1
union
select left(N5,4) from 表1
union
select iif(instr(N5,";")>0,right(left(N5,instr(N5,";")-1),4),iif(instr(N5,",")>0,right(left(N5,instr(N5,",")-1),4),null)) from 表1
union
select iif(instr(N5,";")>0,left(right(N5,len(N5)-instr(N5,";")),4),iif(instr(N5,",")>0,left(right(N5,len(N5)-instr(N5,",")),4),null)) from 表1
union
select right(N5,4) from 表1
union
select left(N6,4) from 表1
union
select iif(instr(N6,";")>0,right(left(N6,instr(N6,";")-1),4),iif(instr(N6,",")>0,right(left(N6,instr(N6,",")-1),4),null)) from 表1
union
select iif(instr(N6,";")>0,left(right(N6,len(N6)-instr(N6,";")),4),iif(instr(N6,",")>0,left(right(N6,len(N6)-instr(N6,",")),4),null)) from 表1
union
select right(N6,4) from 表1
)
where N<>null and isnumeric(N)

附上最后的结果的附件

[ 本帖最后由 Scarlett_88 于 2009-7-17 13:44 编辑 ]

db2.rar

22.51 KB, 下载次数: 7

TA的精华主题

TA的得分主题

 楼主| 发表于 2009-7-18 11:43 | 显示全部楼层
谢谢!!等我调好了,我把最后的贴出来~~
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-17 02:40 , Processed in 0.040106 second(s), 6 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

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