这个SQL语句怎么写?

wanglh 2003-08-20 11:25:40
数据库中有两个表,TA,TB,其结构如下:
TA TB
------------- -----------
A B A B


字段类型A字符串,B整形
要求是:
返回TA中的A,及D(一数值计算结果)
D的值计算方法是在TA.A=TB.A条件下,TB.B<TA.B的个数
不能用分组,返回的行数等于TA中所有的行数
...全文
21 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
rs_net 2003-08-20
  • 打赏
  • 举报
回复
select A,(select count(B) from TB where A=TA.A and B<TA.B) as D from TA
hjb111 2003-08-20
  • 打赏
  • 举报
回复
select *,(select count(*) from tb where tb.a=ta.a and tb.b<ta.b) as 个数 from ta
mistral 2003-08-20
  • 打赏
  • 举报
回复
select A,(select count(*) from tb where a=ta.a and b<ta.b) as D from ta
dafu71 2003-08-20
  • 打赏
  • 举报
回复
select A,(select sum(1) from tb where a=ta.a and b<ta.b) as D from ta
CrazyFor 2003-08-20
  • 打赏
  • 举报
回复
select *,(select count(*) from tb where tb.a=ta.a and tb.b<ta.b) 个数 from ta
pengdali 2003-08-20
  • 打赏
  • 举报
回复
你是要这个吧:
select *,(select count(*) from tb where a=ta.a and b<ta.b) 个数 from ta
pengdali 2003-08-20
  • 打赏
  • 举报
回复
select * from ta,tb where ta.a=tb.a and tb.b<ta.b


select count(*) 个数 from ta,tb where ta.a=tb.a and tb.b<ta.b

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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