select orderid, employeeid,count(orderid) as orderquantity ,orderdate,Customerid  from orders 
where month(orderdate)=month('1996-8-4') and year(orderdate)=year('1996-8-4')
group by Customerid ,orderid, employeeid,orderdate 
order by customerid以NORTHWIND数据库Orders表为例,我想求出1996年8月份的各客户的订购总数,结果总是不对,求教!

解决方案 »

  1.   

    select orderid, employeeid,count(orderid) as orderquantity ,orderdate,Customerid  from orders 
    where datediff(m,orderdate,cast('1996-8-4' as datetime))=0
    group by Customerid ,orderid, employeeid,orderdate 
    order by customerid
      

  2.   

    select orderid, employeeid,count(orderid) as orderquantity ,orderdate,Customerid  from orders 
    where orderdate between cast('1996-7-31' as datetime)  and cast ('1996-9-1' as datetime) Customerid ,orderid, employeeid,orderdate 
    order by customerid
      

  3.   

    这样可以吧select distinct Customerid,count(Customerid) as orderquantity from orders 
    where convert(varchar,orderdate,112) like '199608%'
    group by Customerid
    order by customerid
      

  4.   

    结果:
    ----------------------
    CustomerID orderquantityBERGS 2
    BSBEV 1
    COMMI 1
    LEHMS 2
    LILAS 1
    MAGAA 1
    MORGK 1
    QUEDE 1
    QUICK 3
    RATTC 2
    REGGC 1
    RICAR 1
    ROMEY 2
    SPLIR 1
    TORTU 2
    TRADH 1
    VINET 1
    WARTH 1
      

  5.   

    select Customerid , count(orderid) as orderquantity
    from orders 
    where convert(varchar(7),orderdate,120) = '1996-08'
    group by Customerid
    order by customerid--以NORTHWIND数据库Orders表为例,我想求出1996年8月份的各客户的订购总数,结果总是不对,求教!