Ground factor graph using pure sql