--QQ数据管理库--向QQUser插入数据insertinto[dbo].[QQUser]values('6489390000','b1234567','2019-11-08',2,1)--向Baselnfo插入数据insertinto[dbo].[BaseInfo]values('2000895678','个性男孩','男',20,'河南省','开封','祥符区','13834923932')--查询数据--查询QQ号码为“9473035360”的用户的所有好友信息,包括QQ号码,昵称,年龄select r.RelationQQID as 好友QQ号码,b.NickName as 昵称,b.Age as 年龄
from[dbo].[Relation]as r
innerjoin[dbo].[BaseInfo]as b on(r.RelationQQID=b.QQID)where r.QQID='9473035360'and r.RelationStatus=0--查询当前在线用户信息select*from[dbo].[QQUser]where[Online]=0--查询开封市,年龄在18~45岁的在线用户的信息select*from[dbo].[BaseInfo] b
innerjoin[dbo].[QQUser]as u on(u.QQID=b.QQID)where b.Age>18and b.Age<45and b.City='开封'and u.Online=0--查询昵称为“小笨猪”的用户信息select u.[QQID]as QQ号码,u.passWord as 密码,u.LastLogTime as 最后一次登录时间,u.Online as 在线状态,u.Levei as 用户等级
from[dbo].[QQUser]as u
innerjoin[dbo].[BaseInfo]as b on(u.QQID=b.QQID)where b.NickName='出水芙蓉'--查询QQ号码为6743200008的用户的好友中每个省份的人数,并按照总人数由大到小排序select b.Province as 省份,COUNT(*)as 总人数
from[dbo].[BaseInfo]as b
innerjoin[dbo].[Relation]as r on(r.RelationQQID=b.QQID)where r.QQID='6743200008'and r.RelationStatus=0groupby b.Province
orderbyCOUNT(*)--查询至少有1天没有登录的QQ账号的用户信息,包括QQ号码,最后一次登录时间,等级,昵称,年龄,并按时间的降序排列select u.QQID as 至少2天没有登录的QQ号码,u.LastLogTime as 最后一次登录时间,u.Levei as 等级,b.NickName as 昵称,b.Age as 年龄
from[dbo].[QQUser]as u
innerjoin[dbo].[BaseInfo]as b on(u.QQID=b.QQID)where DATEDIFF(dd,u.LastLogTime,'2019-11-08')>=2orderby u.LastLogTime desc--查询QQ号码为“6743200008”的好友中等级为10级以上的用户信息select r.RelationQQID as 好友QQ号码,b.NickName as 昵称,b.Age as 年龄,e.Levei as 等级
from[dbo].[Relation]as r
innerjoin[dbo].[BaseInfo]as b on(r.RelationQQID=b.QQID)innerjoin[dbo].[QQUser]as e on(r.RelationQQID=e.QQID)where r.QQID='6743200008'and r.RelationStatus=0and e.Levei>10--查询QQ号码为“6743200008”的好友中隐身的用户信息select r.RelationQQID as 隐身的好友号码,b.NickName as 昵称,b.Age as 年龄
from[dbo].[Relation] r
innerjoin[dbo].[BaseInfo]as b on(r.RelationQQID=b.QQID)innerjoin[dbo].[QQUser]as e on(e.QQID=r.RelationQQID)where r.QQID='6743200008'and e.Online=2--查询好友超过20个的用户QQ号码及其好友总数selectCOUNT(*) 好友人数,[QQID]as QQ号码
from[dbo].[Relation]groupby[QQID]havingCOUNT(*)>=2--查询被当作黑名单人物次数排名前20的用户selectCOUNT(*)as 黑名单次数,[RelationQQID]as 用户
from[dbo].[Relation]where[RelationStatus]=1groupby[RelationQQID]--修改数据--修改“2000895678”为隐身update[dbo].[QQUser]set[Online]=2where[QQID]='2000895678'--修改“2000895678”昵称为“被淹死的鱼”地址:“解放中路6号院106室”update[dbo].[BaseInfo]set[Address]='解放中路6号院106室',[NickName]='被淹死的鱼'where[QQID]='2000895678'--将“2000895678”的好友“6743200008”加入黑名单update[dbo].[Relation]set[RelationStatus]=1where[QQID]='2000895678'and[RelationQQID]='6743200008'--把小于20级的用户都提升一个等级update[dbo].[QQUser]set[Levei]=[Levei]+1where[Levei]<20--修改超过365天没有登录的QQ,等级设为-1update[dbo].[QQUser]set[Levei]=-1where DATEDIFF(DD,[LastLogTime],'2019-11-08')>365--好友数量超过20的用户提升一个等级update[dbo].[QQUser]set[Levei]=[Levei]+1where[QQID]in(select Relation.QQID
from[dbo].[Relation]where Relation.RelationStatus=0groupby Relation.QQID
havingCOUNT(Relation.RelationQQID)>=2)--把QQ号码为“6743200008”的用户的好友“被淹死的鱼”拖进黑名单,使用IN关键字模糊查询update[dbo].[Relation]set[RelationStatus]=1where[QQID]='6743200008'and[RelationQQID]=(select[QQID]from[dbo].[BaseInfo]where[NickName]='被淹死的鱼')and RelationStatus=0select*from[dbo].[QQUser]select*from[dbo].[BaseInfo]select*from[dbo].[Relation]--删除数据--把QQ号码为“9473035360”的用户的黑名单中的用户删除deletefrom[dbo].[Relation]where QQID ='9473035360'and[RelationStatus]=1--把QQ号码“2000895678”的用户删除deletefrom[dbo].[Relation]where QQID='2000895678'or RelationQQID='2000895678'deletefrom[dbo].[BaseInfo]where QQID='2000895678'deletefrom[dbo].[QQUser]where[QQID]='2000895678'--将超过1000天没有登录的QQ删除deletefrom[dbo].[Relation]where[QQID]in(select[QQID]from[dbo].[QQUser]where DATEDIFF(DD,[LastLogTime],'2019-11-08')>2)or[RelationQQID]in(select[QQID]from[dbo].[QQUser]where DATEDIFF(DD,[LastLogTime],'2019-11-08')>2)deletefrom[dbo].[BaseInfo]where[QQID]in(select[QQID]from[dbo].[QQUser]where DATEDIFF(DD,[LastLogTime],'2019-11-08')>2)deletefrom[dbo].[QQUser]where[QQID]in(select[QQID]from[dbo].[QQUser]where DATEDIFF(DD,[LastLogTime],'2019-11-08')>2)