标题:请教同组物品查询的方法
只看楼主
njy23000
Rank: 2
等 级:论坛游民
帖 子:7
专家分:18
注 册:2010-11-19
结帖率:0
已结贴  问题点数:20 回复次数:2 
请教同组物品查询的方法
Create  TABLE MAIN.[object_group](
[object_title] varchar(50)
,[object_para] varchar(50)
,[group_title] varchar(50)
,[group_value] varchar(50)
, Primary Key(object_title,object_para,group_title,group_value)   
);

Insert  Into [object_group] ([object_title],[object_para],[group_title],[group_value]) Values("桌子","红木八仙桌","品种","家具");
Insert  Into [object_group] ([object_title],[object_para],[group_title],[group_value]) Values("桌子","红木八仙桌","材质","红木");
Insert  Into [object_group] ([object_title],[object_para],[group_title],[group_value]) Values("桌子","红木八仙桌","包装","一类包装-大");
Insert  Into [object_group] ([object_title],[object_para],[group_title],[group_value]) Values("茶几","红木几","品种","家具");
Insert  Into [object_group] ([object_title],[object_para],[group_title],[group_value]) Values("茶几","红木几","材质","红木");
Insert  Into [object_group] ([object_title],[object_para],[group_title],[group_value]) Values("茶几","红木几","包装","二类包装-中");
Insert  Into [object_group] ([object_title],[object_para],[group_title],[group_value]) Values("桌子","平头案","品种","家具");
Insert  Into [object_group] ([object_title],[object_para],[group_title],[group_value]) Values("桌子","平头案","材质","梨花木");
Insert  Into [object_group] ([object_title],[object_para],[group_title],[group_value]) Values("桌子","平头案","包装","一类包装-大");
Insert  Into [object_group] ([object_title],[object_para],[group_title],[group_value]) Values("椅子","电脑转椅","品种","办公");
Insert  Into [object_group] ([object_title],[object_para],[group_title],[group_value]) Values("椅子","电脑转椅","包装","二类包装-中");
Insert  Into [object_group] ([object_title],[object_para],[group_title],[group_value]) Values("椅子","电脑转椅","材质","革");


[object_title] 对象名称
[object_para] 对象参数
[group_title] 组名称
[group_value] 组取值

求查询语句写法:
输入:对象名称,对象参数
输出:和输入对象至少具有两个相同组名称和组取值的其他对象列表
通俗讲,就是:至少有两个分类定义相同的其他物品

也可以扩充为:有若干个分类定义相同

[ 本帖最后由 njy23000 于 2010-11-19 16:48 编辑 ]
搜索更多相关主题的帖子: 同组 物品 查询 
2010-11-19 11:04
njy23000
Rank: 2
等 级:论坛游民
帖 子:7
专家分:18
注 册:2010-11-19
得分:0 
太寂寞了。
现已解决,答案如下:
SELECT
  object_title ,
  object_para ,
  count( * ) AS cnt
FROM
  (
    SELECT
      a.group_title ,
      a.group_value ,
      b.object_title ,
      b.[object_para]
    FROM
      MAIN.[object_group] a ,
      object_group b
    WHERE
      a.object_title = '桌子' AND a.object_para = '红木八仙桌' AND a.group_title = b.group_title AND a.group_value = b.group_value AND (
        NOT (
          b.object_title = '桌子' AND b.object_para = '红木八仙桌'
        )
      )
  ) c
GROUP BY
  object_title ,
  object_para ;

cnt表示相同分类定义的计数。扩充也解决了。
2010-11-20 09:37
筱晓绾
Rank: 10Rank: 10Rank: 10
来 自:湖南
等 级:贵宾
威 望:12
帖 子:512
专家分:1736
注 册:2010-9-1
得分:20 
呵呵,解决了就好,有时候自己都想想,也能解决的哦!
2010-11-22 13:50



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-326228-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.886854 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved