亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
12下一頁
最近訪問板塊 發(fā)新帖
查看: 3875 | 回復(fù): 13
打印 上一主題 下一主題

求語句 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2007-07-17 10:27 |只看該作者 |倒序?yàn)g覽
系統(tǒng)fedora6 MYSQL5.0.22

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

現(xiàn)將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 [報(bào)告]
發(fā)表于 2007-07-17 11:32 |只看該作者
測(cè)試用代碼:

create table chk(
  user varchar(8) not null,
  ip   char(15)  not null
);

create table act(
  user  varchar(8) not null,
  sttid char(15)  not null
);

insert into act values
('tom','1.1.1.1'),
('James','1.1.1.2'),
('Peter','1.1.1.3'),
('Joe','1.1.1.3');
insert into chk values
('tom',''),
('James',''),
('Peter',''),
('Robot','');

update chk as x
set ip=(select sttid from act as y where x.user=y.user)
where x.user in (select user from act);

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2007-07-17 11:33 |只看該作者
謝謝,我試一下.

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2007-07-17 15:01 |只看該作者
又出現(xiàn)一個(gè)問題,拿fnems的測(cè)試用例來說吧.
      就是act 表中存在user相同的好幾條記錄,表act還存在一個(gè)時(shí)間字段(time).記錄上線時(shí)間
現(xiàn)在的目的就是更新chk表中的ip字段,將act 中user相同的,time時(shí)間為最新時(shí)間的那個(gè)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
5 [報(bào)告]
發(fā)表于 2007-07-17 15:33 |只看該作者
嗯,看看這樣行了吧?  自己感覺效率有點(diǎn)低,呵呵,等待版內(nèi)各高手的答案

create table chk(
  user varchar(8) not null,
  ip   char(15)  not null
);

create table act(
  user  varchar(8) not null,
  sttid char(15)  not null,
  time  int not null
);

insert into act values
('tom','1.1.1.1',1),
('tom','1.1.1.6',2),
('tom','1.1.1.9',4),
('James','1.1.1.2',1),
('Peter','1.1.1.3',1),
('Joe','1.1.1.4',1);
insert into chk values
('tom',''),
('James',''),
('Peter',''),
('Robot','');

select * from act
where (user,time) in
   (select user,max(time) from act group by user);
--  這樣select的話,保證選出來的子集都是“時(shí)間最大的用戶紀(jì)錄”

update chk as x
set ip=(select sttid from act as y
           where x.user=y.user and (user,time) in
             (select user,max(time) from act group by user)
        )
where x.user in (select user from act);


還有,沒有用樓主的命名實(shí)例,是為了少敲點(diǎn)鍵盤,就麻煩樓主自己改一改語句吧

[ 本帖最后由 fnems 于 2007-7-17 15:35 編輯 ]

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2007-07-17 16:10 |只看該作者
UPDATE radcheck,radacct SET radcheck.ipaddr=radacct.CallingStationId WHERE radcheck.username=radacct.username;

ERROR 1054 (42S22): Unknown column 'radacct.username' in 'where clause'

SQL語句中關(guān)鍵字大寫是個(gè)好習(xí)慣,不看錯(cuò)誤提示的人做不好程序員

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2007-07-17 16:24 |只看該作者
再此非常謝謝fnems 的幫忙, 我自己也試著寫了一個(gè).
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);

這個(gè)語句是要寫在配置文件里面的,他是要每十分鐘執(zhí)行一次,所以我想問一下,哪個(gè)執(zhí)行起來更快,不那么耗資源,或者還有沒有更簡(jiǎn)潔更好的寫法,希望幫幫我.

還有就是以前一直是用MSSQL,現(xiàn)在要用MYSQL,雖然基本的語句都類似,但是還有不同的,所以就是想了解一下,這兩種數(shù)據(jù)庫在語句上有那些不同?寫的時(shí)候應(yīng)該注意什么?或者有什么好的忠告???

論壇徽章:
0
8 [報(bào)告]
發(fā)表于 2007-07-17 17:01 |只看該作者

回復(fù) #6 Namelessxp 的帖子

但是我大寫了還是會(huì)這樣,這應(yīng)該就是sql server和mysql 的區(qū)別吧.
mysql> update radcheck set radcheck.ipaddr=radacct.CallingStationId where radcheck.UserName=radacct.UserName;
ERROR 1054 (42S22): Unknown column 'radacct.UserName' in 'where clause'

論壇徽章:
0
9 [報(bào)告]
發(fā)表于 2007-07-17 17:04 |只看該作者
原帖由 liudan182 于 2007-7-17 17:01 發(fā)表
但是我大寫了還是會(huì)這樣,這應(yīng)該就是sql server和mysql 的區(qū)別吧.
mysql> update radcheck set radcheck.ipaddr=radacct.CallingStationId where radcheck.UserName=radacct.UserName;
ERROR 1054 (42S22): Un ...

這樣寫是在做什么?

論壇徽章:
0
10 [報(bào)告]
發(fā)表于 2007-07-17 17:09 |只看該作者
記住一條,用了子查詢就避免用in,因?yàn)樾屎艿汀?br />
如何避免參見:

http://72891.cn/viewthread.php?tid=960762&extra=page%3D2
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP