Sql: select *,EBS+EAS as total,(select Count(distinct EBS+EAS) from Userinfo where EBS+EAS>=a.EBS+a.EAS) as mingci from Userinfo a
小弟一直没弄明白这里面具体是个则么回事 1:from Userinto a 这种连接是属于那种连接?是怎么连的? 2:把上个Sql语句改为select *,EBS+EAS as total,(select Count(distinct a.EBS+a.EAS) from a where EBS+EAS <=a.EBS+a.EAS) as mingci from Userinfo a 为什么就不行?
1:from Userinto a 这种连接是属于那种连接?是怎么连的? -- 可以看作是传了一个查询条件进去即可,应该不是看作连接吧.2:把上个Sql语句改为select *,EBS+EAS as total,(select Count(distinct a.EBS+a.EAS) from a where EBS+EAS <=a.EBS+a.EAS) as mingci from Userinfo a 为什么就不行? -- 你这句写的有问题吧, select *,EBS+EAS as total,(select Count(distinct a.EBS+a.EAS) from [color=#FF0000]a where EBS+EAS <=a.EBS+a.EAS) as mingci from Userinfo a 另外,关于>=和 <=是要看你具体的要求.[/color]
select *,EBS+EAS as total,(select Count(distinct EBS+EAS) from Userinfo where EBS+EAS>=a.EBS+a.EAS) as mingci from Userinfo a ----------- 红色部分相当于一个子查询,只是子查询的where条件中的值a.EBS+a.EAS来源于外层的查询中的每行的对应值而已.
如果说 select *,EBS+EAS as total,(select Count(distinct EBS+EAS) from Userinfo where EBS+EAS>=a.EBS+a.EAS) as mingci from Userinfo a 中的a.EBS+a.EAS相当于外层的每行对应的值,那为什么 select *,EBS+EAS as total,(select Count(distinct a.EBS+a.EAS) from a where EBS+EAS <=a.EBS+a.EAS) as mingci from Userinfo a 中把EBS+EAS理解成外层每行对应的值,对别名表a中进行查询,在a中比EBS+EAS大的数目,为什么就不行呢???
1:from Userinto a 这种连接是属于那种连接?是怎么连的? ---->没有使用连接,这个表示给userinto取一个别名为a2:把上个Sql语句改为select *,EBS+EAS as total,(select Count(distinct a.EBS+a.EAS) from a ---这块当然不行,不存在a这个表,这块不能使用后面的awhere EBS+EAS <=a.EBS+a.EAS) as mingci from Userinfo a 为什么就不行?