如何构建查询字符串

时间:2013-06-04 13:23:34

标签: sql ms-access

我需要为以下问题构建查询字符串 -

  1. 显示批次代码在Sun以及Jamnagar City和Reliance上的记录。
  2. 显示批次代码在Sun和Jamnagar City,Reliance和TATA上的记录。
  3. 我的每周访问表 -

    batch_code    bday             duration          period_no          branch
    B001          Sun                   1            2                  Jamnagar City
    B001          Mon                   1            2                  Jamnagar City
    B001          Tue                   1            2                  Jamnagar City
    B002          Mon                 1.3            4                  TATA
    B002          Mon                 1.3            4                  TATA
    B003          Sun                   1            1                  Jamnagar City
    B003          Mon                   1            1                  Jamnagar City
    B004          Sun                   2            2                  Reliance
    B004          Mon                   2            2                  Reliance
    B004          Tue                   2            2                  Reliance
    B005          Sun                   2            2                  TATA
    B005          Mon                   2            2                  TATA
    B005          Tue                   2            2                  TATA
    B006          Sun                 1.3            4                  Jamnagar City
    B007          Wed                 1.3            4                  Jamnagar City
    

1 个答案:

答案 0 :(得分:1)

  1. SELECT * FROM YourTableName WHERE bday ='Sun'AND(branch ='Jamnagar City'OR branch ='Reliance')

  2. SELECT * FROM YourTableName WHERE bday ='Sun'AND(branch ='Jamnagar City'OR branch ='Reliance'OR branch ='TATA')

  3. 我相信你可以使用IN命令,但如果它在Access中有效,我不肯定。你可以尝试一下。语法是:

    SELECT * FROM YourTableName WHERE bday ='Sun'AND branch IN('Jamnagar City','Reliance','TATA')