我有一个产品平板电脑;因为有几个字段,如subcatid和designerid,分别来自Subcategories和Designers表。网站(ASP.NET C#)管理员可以通过选择designerid或subcatid或两者来在CouponCodes表中插入某种优惠券代码。这意味着如果在CouponCodes表中找到该产品的designerid或subcatid字段或两者,则可以更便宜地销售特定产品。注意,产品不一定具有设计者名称或子蛋白质:管理员可以输入'N / A'作为产品输入; N / A在其各自的表中具有27的设计者和9的subcatid。可能不是最好的数据库设计。
无论如何,这是我在SSMS中的代码;当我尝试执行它时,我得到一个语法错误。如何实现sql?谢谢!
select * from couponcodes
where ( couponcodes.subcatid in
(select subcatid from Products where Products.prodid = 1012)
AND (couponcodes.couponcode = '5braceLets'))
OR
Where ( couponcodes.designerid in
(select designerid from Products where Products.prodid = 1012)
AND (couponcodes.couponcode = '5dora'))
答案 0 :(得分:0)
您有where
两次导致语法错误。你想要做的是
select * from couponcodes
where ( couponcodes.subcatid in
(select subcatid from Products where Products.prodid = 1012)
AND (couponcodes.couponcode = '5braceLets'))
OR
( couponcodes.designerid in
(select designerid from Products where Products.prodid = 1012)
AND (couponcodes.couponcode = '5dora'))