SQL [int]与int

时间:2017-06-26 14:59:34

标签: sql-server tsql

最近我正在使用SQL语言。我找到了两种声明temporary table variables(starting with @)的方法。我的问题是:

它们之间有什么区别吗?

alter session set nls_date_format = 'dd/mm/yyyy';
with
     test_data ( period_no, from_dt, to_dt ) as (
     select 9891, to_date('01/06/2016'), to_date('31/07/2016') from dual union all
     select 9892, to_date('01/08/2016'), to_date('30/09/2016') from dual union all   
     select 9893, to_date('01/09/2016'), to_date('31/10/2016') from dual union all
     select 9894, to_date('01/11/2016'), to_date('31/12/2016') from dual union all
     select 9895, to_date('15/12/2016'), to_date('28/02/2017') from dual union all
     select 9896, to_date('01/03/2017'), to_date('31/05/2017') from dual
     )
-- End of simulated table (for testing purposes only, not part of the solution).
-- SQL query begins BELOW THIS LINE.
select a.period_no as period_a, a.from_dt as from_dt_a, a.to_dt as to_dt_a,
       b.period_no as period_b, b.from_dt as from_dt_b, b.to_dt as to_dt_b
from   test_data a
       join
       test_data b
         on  a.period_no <  b.period_no 
         and a.to_dt     >= b.from_dt
         and b.to_dt     >= a.from_dt
;

  PERIOD_A FROM_DT_A  TO_DT_A      PERIOD_B FROM_DT_B  TO_DT_B  
---------- ---------- ---------- ---------- ---------- ----------
      9892 01/08/2016 30/09/2016       9893 01/09/2016 31/10/2016
      9894 01/11/2016 31/12/2016       9895 15/12/2016 28/02/2017

2 个答案:

答案 0 :(得分:1)

这个例子没有区别。但是,如果您have special characters that need identifying,方括号将用作分隔符 - 例如,如果您将列命名为“First Name”,则需要使用方括号来转义空格字符。

答案 1 :(得分:0)

不是那些都是一样的。用括号键入它只是额外的击键。