免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3823 | 回复: 5
打印 上一主题 下一主题

求语句 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-07-17 10:27 |显示全部楼层 |倒序浏览
系统fedora6 MYSQL5.0.22

radcheck 表 username  ipaddr              2字段
radacct 表 username CallingStationId   2字段

现将2表username相同的记录,从CallingStationId  传到ipaddr 中.

我mysql> update a set a.ipaddr=b.CallingStationId from radcheck a,radacct b where a.username=b.username;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from radcheck a,radacct b where a.username=b.username' at line 1

mysql> update radcheck set radcheck.ipaddr=radacct.CallingStationId where radcheck.username=radacct.username ;
ERROR 1054 (42S22): Unknown column 'radacct.username' in 'where clause'
mysql>

那具体该怎么写??/

论坛徽章:
0
2 [报告]
发表于 2007-07-17 11:33 |显示全部楼层
谢谢,我试一下.

论坛徽章:
0
3 [报告]
发表于 2007-07-17 15:01 |显示全部楼层
又出现一个问题,拿fnems的测试用例来说吧.
      就是act 表中存在user相同的好几条记录,表act还存在一个时间字段(time).记录上线时间
现在的目的就是更新chk表中的ip字段,将act 中user相同的,time时间为最新时间的那个sttid付
给 chk表中的ip字段.

mysql> update radcheck as x set ipaddr=(select CallingStationId from radacct as y where x.username=y.username) where x.username in (select username from radacct) and x.sbm='1' and ipaddr='';
ERROR 1242 (21000): Subquery returns more than 1 row

论坛徽章:
0
4 [报告]
发表于 2007-07-17 16:24 |显示全部楼层
再此非常谢谢fnems 的帮忙, 我自己也试着写了一个.
update chk as x
set ip=(select sttid from (select user,sttid,max(time) time from act group by user)
as y where x.user=y.user) where x.user in (select user from act);

这个语句是要写在配置文件里面的,他是要每十分钟执行一次,所以我想问一下,哪个执行起来更快,不那么耗资源,或者还有没有更简洁更好的写法,希望帮帮我.

还有就是以前一直是用MSSQL,现在要用MYSQL,虽然基本的语句都类似,但是还有不同的,所以就是想了解一下,这两种数据库在语句上有那些不同?写的时候应该注意什么?或者有什么好的忠告???

论坛徽章:
0
5 [报告]
发表于 2007-07-17 17:01 |显示全部楼层

回复 #6 Namelessxp 的帖子

但是我大写了还是会这样,这应该就是sql server和mysql 的区别吧.
mysql> update radcheck set radcheck.ipaddr=radacct.CallingStationId where radcheck.UserName=radacct.UserName;
ERROR 1054 (42S22): Unknown column 'radacct.UserName' in 'where clause'

论坛徽章:
0
6 [报告]
发表于 2007-07-18 19:48 |显示全部楼层
哦,了解了,谢谢大家的帮忙.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP