求一sql,我都想了半天了,没有结果!!!!!
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[t_uid]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[t_uid]
GO
CREATE TABLE [dbo].[t_uid] (
[uid] [int] NOT NULL --单位的编号
) ON [PRIMARY]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[t_pid]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[t_pid]
GO
CREATE TABLE [dbo].[t_pid] (
[pid] [int] NOT NULL , --个人编号
[uid] [int] NULL --单位编号
) ON [PRIMARY]
GO
--给出表t_uid的数据
uid
------------------------------------------------
2001
2002
2003
2004
2005
--给出表t_pid的数据
pid uid
------------------------------------------------
1101 2005
1102 2005
1103 2005
1107 2002
1108 2004
依据t_uid表中的uid字段得出,t_pid表中的uid字段记录有几个,如果没有,那么为0
要求是求一sql,得到结果:就是要显示,uid,uid在t_pid中有几条记录,能写出这样的sql吗,我都想了半天了,没有头绪?
2001 0
2002 1
2003 0
2004 1
2005 3