Try erasing all the codes first and try fixing the firs code that show up. If all codes come up at the same time you should fix the problem on the following order:
P0138 = http://engine-codes.com/p0138_nissan.html Youb may need to replaced the O2 sensor for this problem.
P0400 = http://engine-codes.com/p0400.html Clean the EGR valve and tube for this problem.
P0325 = http://engine-codes.com/p0325_nissan.html You have to replaced the Knock sensor for this problem, but do the other repairs first.