Converted getMarketAverage() function to use out SQLite