`

SQL之AND OR

 
阅读更多

 

 

 select icupatient0_.INTO_ICU_NURSING_LEVEL as col_0_0_,icupatient0_.icu_region_id
     from ICU_PATIENT icupatient0_
    where   
       (to_date(to_char(icupatient0_.INTO_ICU_TIME, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm-dd hh24:mi:ss') <=
          to_date('2014-05-01 00:00', 'yyyy-mm-dd hh24:mi:ss')
      and to_date(to_char(icupatient0_.OUT_ICU_TIME, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm-dd hh24:mi:ss') >=
          to_date('2014-05-01 00:00', 'yyyy-mm-dd hh24:mi:ss')
      ) or (to_date(to_char(icupatient0_.INTO_ICU_TIME, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm-dd hh24:mi:ss') >=
          to_date('2014-05-01 00:00', 'yyyy-mm-dd hh24:mi:ss')
      and to_date(to_char(icupatient0_.INTO_ICU_TIME, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm-dd hh24:mi:ss') <=
         to_date('2014-05-27 23:59:59', 'yyyy-mm-dd hh24:mi:ss'))
       and  icupatient0_.ICU_REGION_ID = 2
   group by icupatient0_.INTO_ICU_NURSING_LEVEL;

 结果:


 

region_id 放到where后面:

 select icupatient0_.INTO_ICU_NURSING_LEVEL as col_0_0_,icupatient0_.icu_region_id
     from ICU_PATIENT icupatient0_
    where   icupatient0_.ICU_REGION_ID = 2 and  
       (to_date(to_char(icupatient0_.INTO_ICU_TIME, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm-dd hh24:mi:ss') <=
          to_date('2014-05-01 00:00', 'yyyy-mm-dd hh24:mi:ss')
      and to_date(to_char(icupatient0_.OUT_ICU_TIME, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm-dd hh24:mi:ss') >=
          to_date('2014-05-01 00:00', 'yyyy-mm-dd hh24:mi:ss')
      ) or (to_date(to_char(icupatient0_.INTO_ICU_TIME, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm-dd hh24:mi:ss') >=
          to_date('2014-05-01 00:00', 'yyyy-mm-dd hh24:mi:ss')
      and to_date(to_char(icupatient0_.INTO_ICU_TIME, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm-dd hh24:mi:ss') <=
         to_date('2014-05-27 23:59:59', 'yyyy-mm-dd hh24:mi:ss'))
       
   group by icupatient0_.INTO_ICU_NURSING_LEVEL;

 结果:icu_region_ID参数只关联or前面查询,结果出错



 
 

  • 大小: 3.7 KB
  • 大小: 3.6 KB
分享到:
评论

相关推荐

    Beginning T-SQL with Microsoft SQL Server 2005 and 2008

    Transact-SQL, or T-SQL, is Microsoft Corporation’s powerful implementation of the ANSI standard SQL database query language, which was designed to retrieve, manipulate, and add data to relational ...

    SQL 语法 SQL 总结 SQL教程

    SQL AND & OR SQL Order By SQL insert SQL update SQL delete SQL 高级 SQL Top SQL Like SQL 通配符 SQL In SQL Between SQL Aliases SQL Join SQL Inner Join SQL Left Join SQL Right Join SQL ...

    sql and pl/sql

    - **逻辑运算子**:如`AND`、`OR`、`NOT`等,用于组合条件表达式。 - **虚拟栏位(Pseudo-columns)**:如`ROWNUM`等,用于提供额外的信息而非表中的实际列。 #### 三、单行函数 - **字符串函数**:如`UPPER`、`...

    SQL Injection Attacks and Defense

    2. **恶意输入**:攻击者会构造特殊的字符串作为输入,这些字符串可能包含SQL关键字或者特殊字符,例如`' OR 1=1 --`这样的字符串可以被用来构造一个始终为真的条件,从而绕过认证机制。 3. **执行非授权操作**:...

    第十六节 绕过剔除and和or的SQL注入-01

    绕过剔除and和or的SQL注入 SQL注入是一种常见的Web应用程序安全漏洞,攻击者可以通过在输入字段中插入恶意SQL代码来访问或修改数据库中的敏感信息。为了防止SQL注入,开发者需要对用户输入进行严格的验证和过滤。...

    SQL Injection Attacks and Defense.pdf

    SELECT * FROM users WHERE username = '' OR '1'='1' AND password = '$password'; ``` 这将导致所有用户的记录被返回,因为`'1'='1`总是为真。 #### 六、最佳实践 1. **定期审计**:定期对应用程序的源代码进行...

    Joe Celko’s Trees and Hierarchies in SQL for Smarties

    SQL is the de facto standard for database retrieval, and if you need to access, update, or utilize data in a modern database management system, you will need SQL to do it. The Second Edition of Joe ...

    and or between and 的万能查询方法

    本文将深入探讨如何利用SQL及HQL(Hibernate Query Language)中的AND、OR与BETWEEN关键字构建复杂查询,以满足项目中多条件筛选的需求。通过分析给定的代码片段,我们将详细了解如何在实际应用中运用这些关键字,...

    SQLQuery2.sql

    sql数据类型,MYSQL,SQLSERVER,ORACLE练习SQL,各种数据类型,SQL SELECT DISTINCT 语句,SQL AND & OR 运算符,SQL AND & OR 运算符

    [SQL工具] Red Gate SQL Toolbelt 2013.1.8.2.353

    The SQL Toolbelt allows developers and DBAs to gain access to our essential SQL Server tools. This means that when you are working with SQL Server databases, you can finally have the most powerful set...

    Professional Microsoft SQL Server 2016 Reporting Services and Mobile Reports 代码

    Whether you're starting from scratch or simply upgrading, this book is an essential guide to report design and business intelligence solutions. Understand BI fundamentals and Reporting Services ...

    SQL Injection Attacks and Defense 2nd Edition

    通过阅读《SQL Injection Attacks and Defense 2nd Edition》这本书,读者能够深入理解SQL注入攻击的各种变体及其防御方法,从而提高自身在SQL方面的技能水平。本书不仅提供了理论知识,还包含了丰富的实战案例分析...

    SQL语句中OR和AND的混合使用的小技巧

    在SQL查询中,AND和OR是两种常用的逻辑运算符,用于组合多个条件以过滤结果集。它们在构建复杂的查询语句时发挥着关键作用。然而,如果不正确地使用,可能会导致预期之外的结果。下面我们将详细探讨如何混合使用AND...

    关于SQL语句中的AND和OR执行顺序遇到的问题

    问题的根结在SQL语句的AND和OR关键字的执行优先级问题。下面就针对这个问题进行一下测试。 场景 1、有一张学生表Student,表字段包括Id(用户主键)、Name(用户名)、Grade(年级)、Class(班级)、Sex(性别)。...

    Professional SQL Server 2012 Analysis Services with MDX and DAX part2

    If youre a database or data warehouse developer, this is the expert resource you need to build full-scale, multi-dimensional, database applications using Microsofts new "SQL Server 2012 Analysis ...

    Microsoft SQL Server Native Client (SQL Native Client)

    Its use of native code API (ODBC, OLE DB and ADO) to connect to Microsoft SQL Server 7.0,2000 or 2005 applications to provide run-time support. SQL Native Client should be used to create new ...

    10分钟学会SQL Sams Teach Yourself SQL in 10 Minutes

    Sams Teach Yourself SQL in 10 Minutes has established itself as the ... All examples have been tested against each SQL platform, with incompatibilities or platform distinctives called out and explained.

Global site tag (gtag.js) - Google Analytics