日期:2014-05-18  浏览次数:20424 次

请高手看下,关于表设计的。谢谢
我做的是产品二级分类,这是我建的表 
create table productClass  

 pcId int identity(1,1), 
 pcBig varchar(50),--大类别 
 parentId int,  
 pcSmall varchar(50)--小类别 

1 笔记本 0 NULL 
2 品牌 0 NULL 
3 价位段 0 NULL 
4 屏幕大小 0 NULL 
6 NULL 1 基本用途型 
7 NULL 1 轻巧型 
8 NULL 1 娱乐型 
9 NULL 1 商务型 
10 NULL 2 SONY 
11 NULL 2 HP 
就是用后台GRIDVIEW绑定管理分类信息。绑定格式: 
小类别 所属的大类别 操作 
。。。 。。。 。。 
。。。 。。。 。。 
。。。 。。。 。。 
我写的SQL语句是:select * from productClass where pcId in(select distinct parentId from productClass where parentId!=0 )但只能显示大类别,小类别显示不了,它为NULL。该怎么写SQL语句? 


------解决方案--------------------
if object_id('productClass') is not null 
drop table productClass 
if object_id('f_getLarge') is not null 
drop function f_getLarge 
go 
create table productClass
(
 pcId int identity(1,1),
 pcBig varchar(50),--大类别
 parentId int,
 pcSmall varchar(50)--小类别
)
insert into productClass 
select '笔记本', 0, NULL union all
select '品牌', 0, NULL union all
select '价位段', 0, NULL union all
select '屏幕大小', 0, NULL union all
select null, 1, '基本用途型' union all
select null, 1, '轻巧型' union all
select null, 1, '娱乐型' union all
select null, 1, '商务型' union all
select null, 2, 'SONY' union all
select null, 2, 'HP' 
--select * from productClass 
--小类别 所属的大类别 操作 
go 
create function f_getLarge(@largeID int) 
returns varchar(100) 
as 
begin 
declare @LargeName varchar(100) 
select @LargeName=pcBig from productClass where pcId=@largeID 
return @LargeName 
end 
go 
select pcSmall as 小类别,dbo.f_getLarge(parentId) as 所属的大类别 from productClass where pcSmall is not null 


接分了
------解决方案--------------------
接分了
------解决方案--------------------