SELECT TO_CHAR (date_blabla, 'DD-MON-YYYY') as column1
,column2
,column3
,column4
,column5
,column6
,CASE
WHEN blabla IN
('1','10','101','1069211','1091116','11','110','13','14','18',
'19','2','20',,'97') THEN 'yes'
ELSE 'lol'
END AS column7
,DateDiff(hours, column5, column6) AS RCV_Time
,CASE
WHEN RCV_Time BETWEEN -2000 AND 24 THEN '0-24'
WHEN RCV_Time BETWEEN 24 AND 48 THEN '24-48'
WHEN RCV_Time BETWEEN 48 AND 72 THEN '48-72'
WHEN RCV_Time BETWEEN 72 AND 96 THEN '72-96'
WHEN RCV_Time BETWEEN 96 AND 120 THEN '96-120'
WHEN RCV_Time BETWEEN 120 AND 144 THEN '120-144'
WHEN RCV_Time BETWEEN 144 AND 168 THEN '144-168'
WHEN RCV_Time > 168 THEN '>168'
ELSE 'no'
END AS Ranges
FROM yes.yes
WHERE 1 = 1
AND date_blabla >= DateAdd(Days, 1 - 31 , TO_DATE('{RUN_DATE_YYYYMMDD}', 'YYYYMMDD'))
AND date_blabla < DateAdd(Days, 1, TO_DATE('{RUN_DATE_YYYYMMDD}', 'YYYYMMDD'))
我需要列RCV_Time来计算列范围,但是我不希望该列出现在最终查询中。我需要以某种方式隐藏该列。
答案 0 :(得分:3)
您可以select a,b,c from (select a,b,c,d,e,f,g,h from blah) alias_here
但是对于您而言,请不要使用该列,例如:
SELECT TO_CHAR (date_blabla, 'DD-MON-YYYY') as column1
,column2
,column3
,column4
,column5
,column6
,CASE
WHEN blabla IN
('1','10','101','1069211','1091116','11','110','13','14','18',
'19','2','20',,'97') THEN 'yes'
ELSE 'lol'
END AS column7
,CASE
WHEN DateDiff(hours, column5, column6) BETWEEN -2000 AND 24 THEN '0-24'
WHEN DateDiff(hours, column5, column6) BETWEEN 24 AND 48 THEN '24-48'
WHEN DateDiff(hours, column5, column6) BETWEEN 48 AND 72 THEN '48-72'
WHEN DateDiff(hours, column5, column6) BETWEEN 72 AND 96 THEN '72-96'
WHEN DateDiff(hours, column5, column6) BETWEEN 96 AND 120 THEN '96-120'
WHEN DateDiff(hours, column5, column6) BETWEEN 120 AND 144 THEN '120-144'
WHEN DateDiff(hours, column5, column6) BETWEEN 144 AND 168 THEN '144-168'
WHEN DateDiff(hours, column5, column6) > 168 THEN '>168'
ELSE 'no'
END AS Ranges
FROM yes.yes
WHERE 1 = 1
AND date_blabla >= DateAdd(Days, 1 - 31 , TO_DATE('{RUN_DATE_YYYYMMDD}', 'YYYYMMDD'))
AND date_blabla < DateAdd(Days, 1, TO_DATE('{RUN_DATE_YYYYMMDD}', 'YYYYMMDD'))
答案 1 :(得分:2)
按如下所示使用上方查询(选择所需的列)
select x.column1,x.column2 from (
SELECT TO_CHAR (date_blabla, 'DD-MON-YYYY') as column1
,column2
,column3
,column4
,column5
,column6
,CASE
WHEN blabla IN
('1','10','101','1069211','1091116','11','110','13','14','18',
'19','2','20',,'97') THEN 'yes'
ELSE 'lol'
END AS column7
,DateDiff(hours, column5, column6) AS RCV_Time
,CASE
WHEN RCV_Time BETWEEN -2000 AND 24 THEN '0-24'
WHEN RCV_Time BETWEEN 24 AND 48 THEN '24-48'
WHEN RCV_Time BETWEEN 48 AND 72 THEN '48-72'
WHEN RCV_Time BETWEEN 72 AND 96 THEN '72-96'
WHEN RCV_Time BETWEEN 96 AND 120 THEN '96-120'
WHEN RCV_Time BETWEEN 120 AND 144 THEN '120-144'
WHEN RCV_Time BETWEEN 144 AND 168 THEN '144-168'
WHEN RCV_Time > 168 THEN '>168'
ELSE 'no'
END AS Ranges
FROM yes.yes
WHERE 1 = 1
AND date_blabla >= DateAdd(Days, 1 - 31 , TO_DATE('{RUN_DATE_YYYYMMDD}', 'YYYYMMDD'))
AND date_blabla < DateAdd(Days, 1, TO_DATE('{RUN_DATE_YYYYMMDD}', 'YYYYMMDD'))
) x