Wednesday, 15 June 2016

Netezza SQL Interview Questions and Answers - Part 1


1.    How do you verify whether table has latest statistics?

SELECT tablename, CASE WHEN recent::smallint in (85,341,149) THEN 'UP TO DATE'
ELSE 'OUT DATED' END::CHAR(10) AS Stat_State
FROM _v_statistic

2.    How delete duplicate records from database?

delete from TEST t1
where rowid <> (select max(rowid) from test t2 where t1.id = t2.id )

3.    How do you transpose table?
Use case or decode statement to transpose table
select
   product,
    sum(case when year = 2010 then sales end) as year_2010,
    sum(case when year = 2011 then sales end) as year_2011,
    sum(case when year = 2012 then sales end) as year_2012,
    sum(case when year = 2013 then sales end) as year_2013
from sales
group by product;

4.    Logic to get first day of month?

select day(last_day(now() - interval '1 month')+ interval '1 day');

5.    Logic to get last day of previous month?


select last_day(now() - interval '1 month');

Related Articles:

No comments:

Post a Comment