◆求一经典的SQL语句

huaerinfo 2006-01-17 09:25:02
数据库现在以下内容:
name explain
abc aa;100;101;102;...
bcd bb;001;002;003;...

现在需要查询得出这样的结果:
name explain
bcd 001
abc 100

其中,001是从explain中的第二个分号取到的,100也是如此。
并且取出来后还需按照一定的排序得出(就如001在先,100在后)
请高手指教,帮忙,谢谢。。。
...全文
147 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
yelanne 2006-01-17
  • 打赏
  • 举报
回复
建議建個臨時表 如:temptable
CREAT TABLE TEMPTABLE(……)
字段: name , explain_add
設原表 table1

str1="select name,explain from table1"
set rs=conn.excute (str1)
if not rs.eof then
do while not rs.eof
tempname=rs("explain")
tempstr=rs("explain")
getstr=split(tempstr,";")
str2="insert into temptable (name,explain_add) values ('"&tempname&"','"&getstr(1)&"')"
conn.excute (str2)

rs.movenext
loop
end if

str3="select a.name,b.explain_add from table1 a, temptable b where a.name=b.name order by b.explain_add"
set rs3=conn.excute (str3)
……
  • 打赏
  • 举报
回复
select name,substring(explain,4,6) from tab1 order by substring(explain,4,6)
huaerinfo 2006-01-17
  • 打赏
  • 举报
回复
555
高手呢?
。。。
huaerinfo 2006-01-17
  • 打赏
  • 举报
回复
谢谢。
我也知道有这些函数,但如果运用起来仍需一定的技巧。。
继续等待。。
hyq8848 2006-01-17
  • 打赏
  • 举报
回复
提供几个函数 可共参考
substring(字段,开始长度,结束长度)
像 stoff,len ,left ,right 你应该知道吧
37350792 2006-01-17
  • 打赏
  • 举报
回复
"aa;100;101;102;"...用substring() ,indexof() 及order by 的方法组合起为使用就可以做到了!你可以查一下帮助,很简单的!
huaerinfo 2006-01-17
  • 打赏
  • 举报
回复
星星的兄弟也来了。。
那我现在用SQL语句,可不可以写出来啊?
  • 打赏
  • 举报
回复
为什么不用符合范式要求的?
huaerinfo 2006-01-17
  • 打赏
  • 举报
回复
55。。
顶下先。
huaerinfo 2006-01-17
  • 打赏
  • 举报
回复
yelanne(风) 的构思可以,不过麻烦啊。。
执行速度又慢了好多了。
huaerinfo 2006-01-17
  • 打赏
  • 举报
回复
liuxiaoyi666(MSMVP)
select name,substring(explain,4,6) from tab1 order by substring(explain,4,6)
不行啊,全是乱符。。

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧