Featured post
database partitioning - SQL complex view for virtually showing data -
i have table following table.
---------------------------------- hour location stock ---------------------------------- 6 2000 20 9 2000 24 ----------------------------------
so shows stock against of hours in there change in quantity. requirement create view on table virtually show data (if stock not htere particular hour). data should shown
---------------------------------- hour location stock ---------------------------------- 6 2000 20 7 2000 20 -- same hour 6 stock 8 2000 20 -- same hour 6 stock 9 2000 24 ----------------------------------
that means if data not there particular hour should show last hour's stock having stock. , have table available hours 1-23 in column.
i have tried partition on method given below. think missing thing around requirement done.
select hour_number, case when total_stock null sum(total_stock) on ( partition location order current_hour rows 1 preceding ) else total_stock end full_stock ( select hour_number hour_number hours_table -- refeerence table hours 1-23 group 1 ) hours_ref left outer join ( sel current_hour current_hour , stock total_stock ,location location stock_table stock<>0 ) stocks on hours_ref.hour_number = stocks.current_hour
this query giving hours stock null hours without data. looking @ ansi sql solution can used on databases teradata.
i thinking using partition on wrongly or there other way. tried case when needs kind of looping check hour stock.
i've run similar problems before. it's simpler make sure data need somehow gets database in first place. might able automate stored procedure runs periodically.
having said that, did consider trying coalesce() scalar subquery? (or whatever similar function dbms supports.) i'd try myself , post sql, i'm leaving work in 2 minutes.
- Get link
- X
- Other Apps
Comments
Post a Comment