有一个表格
Rental_Out Rental_Due Rental_Returned
2004-03-12 2004-03-19 2004-03-14
2004-03-12 2004-03-19
2004-03-11 2004-03-18
2004-03-10 2004-03-17
2004-03-10 2004-03-17
2004-03-09 2004-03-16
2004-03-12 2004-04-13
2004-03-08 2004-03-09
2004-02-02 2004-02-02 2004-02-02 求List the details of rentals that occurred in March 2004SQL

解决方案 »

  1.   

    What is the meaning of this list and action?
      

  2.   

    大概逻辑就是这样,字段你自己调整----------------------------------------------------------------
    -- Author  :DBA_Huangzj(發糞塗牆)
    -- Date    :2013-05-26 23:56:00
    -- Version:
    --      Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (Intel X86) 
    -- Jun 17 2011 00:57:23 
    -- Copyright (c) Microsoft Corporation
    -- Enterprise Edition on Windows NT 6.1 <X86> (Build 7601: Service Pack 1)
    --
    ----------------------------------------------------------------
    --> 测试数据:[huang]
    if object_id('[huang]') is not null drop table [huang]
    go 
    create table [huang]([Rental_Out] datetime,[Rental_Due] datetime,[Rental_Returned] datetime)
    insert [huang]
    select '2004-03-12','2004-03-19','2004-03-14' union all
    select '2004-03-12','2004-03-19',null union all
    select '2004-03-11','2004-03-18',null union all
    select '2004-03-10','2004-03-17',null union all
    select '2004-03-10','2004-03-17',null union all
    select '2004-03-09','2004-03-16',null union all
    select '2004-03-12','2004-04-13',null union all
    select '2004-03-08','2004-03-09',null union all
    select '2004-02-02','2004-02-02','2004-02-02'
    --------------开始查询--------------------------select * from [huang]
    WHERE '2004-03-01'<=[Rental_Returned] AND '2004-03-31'>=[Rental_Out]
    ----------------结果----------------------------
    /* 
    Rental_Out              Rental_Due              Rental_Returned
    ----------------------- ----------------------- -----------------------
    2004-03-12 00:00:00.000 2004-03-19 00:00:00.000 2004-03-14 00:00:00.000
    */
      

  3.   

    有一个表格
    Item_Type Item_Charge
    O/night $5.00
    7nights $4.00
    7nights $4.00
    Weekly $3.00
    Weekly $3.00
    Weekly $3.00
    Weekly $3.00
    O/night $5.00
    7nights $4.00
    Weekly $3.00
    Weekly $3.00
    O/night $5.00
    7nights $4.00Calculate the cost of hiring any of the weekly items for 2 weeks.
    计算2周的价钱。