以下操作都是在SQLServer2000的Northwind数据库中所涉及的表均在原有的数据库中
6、求出 1996 年中,最好卖的前10种产品的信息。(提示:年份OrderData在Orders表中,卖的数量在Order Details表中,产品的信息在product表中)
-------------------------------------------------------------------------------
7、在orders表中,求出freight总和最大的customers表的customers的姓名。用子查询语句完成(用子查询完成,并截图)这是我写的
Select contactname from customers
Where customerid in( select customerid from orders group by customerid having max(freight))Select contactname from customers
Where customerid exists (select customerid from orders  group by customerid having  max(freight) )

解决方案 »

  1.   


    SELECT TOP 10 SUM(QTY) AS SUMQTY,product FROM OrderDetails GROUP BY product ORDER BY SUMQTY DESC手頭上沒有Northwind庫 將就看
      

  2.   

    select top 10 a.quantity,b.productname 
    from [Order Details] a left join products b on a.productid=b.productid
                           left join orders c on a.orderid=c.orderid
    where year(c.orderdate)='1996'
    order by a.quantity descquantity productname                              
    -------- ---------------------------------------- 
    120      Pâté chinois
    100      Steeleye Stout
    80       Teatime Chocolate Biscuits
    80       Camembert Pierrot
    80       Escargots de Bourgogne
    80       Vegie-spread
    77       Gula Malacca
    70       Northwoods Cranberry Sauce
    70       Northwoods Cranberry Sauce
    70       Gorgonzola Telino(所影响的行数为 10 行)
      

  3.   

    老实说,并不了解Northwind这个库里面的那些字段代表什么意思。
      

  4.   

    select a.companyname 
    from customers a
    where customerid =( select customerid 
                        from orders 
                        where freight=( select max(freight) 
                                        from orders))companyname                              
    ---------------------------------------- 
    QUICK-Stop(所影响的行数为 1 行)
      

  5.   


    6。select productname from products
    where productid in (
    select top 10 productid from [Order Details] where orderid in
    (select orderid from orders where datepart(yy,OrderDate)=1996)
    group by productid order by count(1) desc)7。select CompanyName from customers where customerid in
    (select top 1 customerid from orders group by customerid order by sum(freight) desc)
      

  6.   


    6的结果:
    Gorgonzola Telino
    Mozzarella di Giovanni
    Guaraná Fantástica
    Camembert Pierrot
    Tarte au sucre
    Flotemysost
    Raclette Courdavault
    Tourtière
    Scottish Longbreads
    Chang7的结果:
    Save-a-lot Markets