求sql语句 - MS-SQL Server / 基础类
两个表 B 表的fd_person_id 与A表中的fd_id关联如下
A表
fd_id name
1 a
2 b
3 c
B表
fd_id fd_person_id
1 1
2 2
现在要判断 给定一个 A表的 NAME 判断这个name 是否存在与A表中又不存在于B表中
比如 给name 为c 返回的count 为1 给a b d e 等都返回0
谢谢
SQL code:
select * from a where not exists (select 1 from b where a.fd_id=b.fd_id)
and a.name='c'
SQL code:
select count(1) as cnt from b where exists(select 1 from a where a.fd_id= b.fd_person_id and name='c')
SQL code:
select name,num=count(*)
from A left join B on A.fd_id=B.fd_person_id
where B.fd_id is null and name='c'
group by name
ths
相关问答:
我一个项目,有个插入操作,具体是这样的:
我有进货信息表。在出货时选择相应的进货信息,输入数量,选择部门后,点保存按钮,由于网络延时,点一下没有反映,于是用户就又点一下,导致一次插入了两条记录:
例:
......
今天做了一个存储过程 环境是SQL2000数据库
大致如下
建立临时表
定义员工游标
循环员工(属于1个公司)
......
现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......
字段1,字段2.....字段N,Status,ParentID
1,Name1....test1,1,99
1,Name1....test1,3,99
1,Name2....test2,1,101
1,Name2....test2,3,101
1,Name3....test3,2,101
1,Name1....test1,4,101
想要的结果是:
1,Na ......
求个vb中的sql语句的写法,次sql语句的用法是分页程序
我写的如下:其中A是用来接收每页显示的记录的条数,B是用来接收显示的当前的页面.
sqltext="select top A * from log where id not in(select top ( ......