Can';不要进行SQL查询

Can';不要进行SQL查询,sql,subquery,Sql,Subquery,我的任务是: 选择1988年价格至少变动两次的产品说明 我的代码: select description from PRODUCT join price on product.product_id = price.product_id where price.product_id = (select product_id from price having count(product_id)>1) 数据库结构 您使用的是什么数据库管理系统 我认为您可

我的任务是:
选择1988年价格至少变动两次的产品说明
我的代码:

    select description from PRODUCT 
    join price on product.product_id = price.product_id 
    where price.product_id = (select product_id from price having 
    count(product_id)>1)
数据库结构


您使用的是什么数据库管理系统

我认为您可以删除对
price
的连接,因为您不需要它,请将where子句中的
=
运算符更改为
中的
,并为年份添加一个条件,如下所示:

select description
from PRODUCT
where product_id in (
  select product_id
  from price
  where to_char(start_date,'YYYY')='1988'
  group by product_id
  having count(product_id)>1
)

假设您使用的是Oracle,我认为这会起作用。只需更改特定于DBMS的部分,尤其是当年的条件。

假设您正在使用advantureWork2012数据库连接两个表,其中 ProductID是您的加入密钥

由于您正在使用子查询with=将出现此错误

(Msg 512,级别16,状态1,第8行子查询返回的值超过1。)
值。当子查询后跟=,!=,您使用的是哪种产品?“SQL”时,这是不允许的只是一种查询语言,而不是特定数据库产品的名称。请为您正在使用的数据库产品添加一个IN子句。使用
where price.product\u id IN(子查询)
这里的
price
是什么意思?在子查询中添加一个GROUP BY!并输入。这如何解释“哪些价格在1988年至少更改了两次”“对不起,我的意思是,你建议的查询不考虑只检索产品的要求,在1988中价格至少改变了两次。查询在“价格”表中返回至少两次出现的所有产品。
    Select product.description From PRODUCT 
    Join price On product.product_id = price.product_id 
    where price.product_id In (select product_id from price group by 
    product_id having count(product_id)>1 and Year(Start_Date)>1988)