初学者求一条sql语句,结贴,

菜鸟求一条sql语句,在线等结贴,急啊!~~~~~
编号 产品名 数量
1 牛仔裤 1
1 外套 2
2 牛仔裤 1
2 外套 2
3 牛仔裤 3
3 外套 1
3 内衣 1
4 牛仔裤 1
5 内衣 1
.
.
.
n 内衣 1
我现在要统计出:1.只买了牛仔裤的用户编号
  2.即买牛仔裤又买了内衣的用户编号

------解决方案--------------------
1
SELECT * from ttp1 a where not exists(select 1 from ttp1 where 编号=a.编号 and 产品名 in('外套','内衣'))
and 产品名='牛仔裤'

2
SELECT * from ttp1 a where exists(select 1 from ttp1 where 编号=a.编号 and 产品名 in('内衣'))
and 产品名='牛仔裤'
------解决方案--------------------
1.只买了牛仔裤的用户编号
SQL code
select distinct 编号 from table1 a
where 产品名='牛仔裤'
and not exists (select 1 from table1 where 编号=a.编号 and 产品名!='牛仔裤')

------解决方案--------------------
2.即买牛仔裤又买了内衣的用户编号

SQL code
select distinct a.编号
from table1 a ,table1 b
where a.编号=b.编号
and a.产品名='牛仔裤' and b.产品名='内衣'

------解决方案--------------------
SELECT * from ttp1 a where exists(select 1 from ttp1 where 编号=a.编号 and 产品名='内衣') and not exists(select 1 from ttp1 where 编号=a.编号 and 产品名='外套')
and 产品名='牛仔裤'