sql - Select same number of rows even if data is not there -



sql - Select same number of rows even if data is not there -

i want write query select same number of rows, if info not there. if info not there, still select in place.

for example, if want select amount in bank business relationship lastly 5 years, have info lastly 3 years, still select 5 rows , have 0's 2 missing years?

class="lang-none prettyprint-override">| year | balance | | 2014 | $5 | | 2013 | $10 | | 2012 | $31 | | 2011 | $0 | << doesn't exist | 2010 | $0 | << doesn't exist

is possible? help.

using mssql, work. there other similar functions other dbs. select top 5 year, isnull(balance,0) yourtable

sql select

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -