有两张表,第一张是父表(产品表)字段是:产品编号,产品名称,产品价格  第二张是子表 字段是:购买产品的编号(外键引用产品表中的产品编号),买家姓名,购买数量,购买价格   题目是如何查出没有卖出过的商品名称

解决方案 »

  1.   

    select 产品名称 from 产品表 a left join 卖出表 b 
    on a.产品编号=b.购买产品的编号
    where b.购买产品的编号 is null 
      

  2.   

    select * from 产品表 a where not exists(
    select 1 from b where a.产品编号=b.产品编号
    )select * from 产品表  where 产品编号 not in(
    select 产品编号 from b )
      

  3.   

    select 产品名称 from 产品表 t where not exists(select 1 from 子表 where 购买产品的编号=t.产品编号)
      

  4.   


    select m.* from 父表 where 产品编号 not in (select distinct 购买产品的编号 from 子表)
      

  5.   

    select m.* from 父表 m where 产品编号 not in (select distinct 购买产品的编号 from 子表)select m.* from 父表 m where not exists (select 1 from 子表 n where n.购买产品的编号 = m.产品编号 )
      

  6.   

    select 产品名称
    from 父表 a
    where not exists(select * from 字表 where a.产品编号=购买产品的编号)
      

  7.   

    select 产品名称 from 父表 t where not exists(select 1 from 子表 where 购买产品的编号=t.产品编号)
      

  8.   


    create table product
    (
     productID varchar(20),
     productName varchar(50),
     productPrice decimal
    )
    create table procductchild
    (
     childID varchar(20),
     childName varchar(50),
     childCount int,
     childPrice decimal
    )
    insert into product(productID,productName,productPrice)
    (
     select '100101','aa',45 union
     select '100102','bb',100 union
     select '100103','cc',78 union
    select '100104','dd',67 union
    select '100105','ee',53
    )
    insert into procductchild(childID,childName,childCount,childPrice)
    (
      select '100101','jack',4,40 union
    select '100102','zhangsan',74,100 union
    select '100101','lisi',10,40 union
    select '100103','liudehua',53,78 union
    select '100103','zhangxueyou',75,78 union
    select '100102','hehui',42,100 
    )
    有两张表,第一张是父表(产品表)字段是:产品编号,产品名称,产品价格
     第二张是子表 字段是:购买产品的编号(外键引用产品表中的产品编号),
    买家姓名,购买数量,购买价格 题目是如何查出没有卖出过的商品名称 
    select * from(
    select p.productName,isnull(c.childCount,0) as childCount from product p 
    left join procductchild c on p.productID=c.childID) as product where product.childCount=0
    go
      

  9.   

    create table A
    (
     productID varchar(20),
     productName varchar(50),
     productPrice decimal
    )
    create table B
    (
     childID varchar(20),
     childName varchar(50),
     childCount int,
     childPrice decimal
    )
    insert into A(productID,productName,productPrice)
    (
     select '100101','aa',45 union
     select '100102','bb',100 union
     select '100103','cc',78 union
    select '100104','dd',67 union
    select '100105','ee',53
    )
    insert into B(childID,childName,childCount,childPrice)
    (
      select '100101','jack',4,40 union
    select '100102','zhangsan',74,100 union
    select '100101','lisi',10,40 union
    select '100103','liudehua',53,78 union
    select '100103','zhangxueyou',75,78 union
    select '100102','hehui',42,100  
    )select productName from A
    where product