0

これらは私のテーブルです:

User, Product, DiscountGroup, DiscountUser, DiscountProduct.

割引商品:

id    discountGroupId    productId     discount
---   --------------     ---------     -------
1        2                8             2000
2        3                8             1000
3        2                4              4500

割引ユーザー:

id    discountGroupId    userId   
---   --------------     --------- 
1        2                2        
2        3                3        
3        2                2    

割引グループ:

id    title   active
---   ------ --------     
1       A      1         
2       B      0       
3       C       1    

SQL Server 2000 を使用しています。

私が欲しいもの:

最初に、各 productid と member について、両方が属する discountGroup を見つけます。

私は私のクエリを書きます:

select * 
from discountGroup 
where id in (select discountgroupId 
             from discountproduct 
             where productid = 11)
  and id in (select discountgroupId 
             from discountuser 
             where userid = 2)
  and active = 1

2 番目: 特別な製品とメンバーの最大割引を見つけたい。

どうすればいいですか?

3 番目: 特別なユーザーとすべての製品について、最適な割引と割引グループを見つけたい タイトル:

これと同じ:

user  produc    discount   discountGroup
---   -----     -------    ------------
ali   phone     400            A
reeza mobile     200           B 
4

1 に答える 1