select skyLevel, 
photZPCat-2.5*log10(5.0*skyNoise*sqrt(3.141593*1.2)/(CA.xPixSize*M.expTime))
-AperCor3 
as depth, MFD.multiframeID,mfd.extNum,photZPCat,seeing*xPixSize as 
seeing,skyLevel,skyNoise,avStellarEll,(amStart+amEnd)/2.0 as airMass, 
M.expTime, M.njitter, M.nustep, aperCor3, M.project, M.utDate, T.*,project 
from MultiframeDetector as MFD, CurrentAstrometry as CA, Multiframe AS M, 
(select D.multiframeID,avg(seeing*xPixSize) as avgSee,avg(photZPCat) as 
avgZP,avg(aperCor3) as avgAperCor3, avg(skyLevel) as avgSkyLevel, 
avg(skyNoise) as avgSkyNoise, avg(avStellarEll) as avgEll, avg(C.l) as 
avl, avg(c.b) as avb, avg(c.centralDec) as avgDec, avg(c.centralRA) as 
avgRA, 
avg(photZPCat-2.5*log10(5.0*skyNoise*sqrt(3.141593*1.2)/(C.xPixSize*M.expTime))
-AperCor3) 
as avgDepth FROM MultiframeDetector AS D, Multiframe AS M, 
CurrentAstrometry AS C WHERE project like '%uhs%' AND seeing>0.0 AND 
C.MultiframeID=M.MultiframeID AND C.extNum=D.extNum AND xPixSize>0.0 AND 
M.MultiframeID=D.MultiframeID AND M.utDate between '2017-01-31' and 
'2018-01-31' and M.deprecated=0 and D.deprecated=0 group by 
D.multiframeID) as T where MFD.MultiframeID=CA.MultiframeID and 
MFD.extNum=CA.extNum and M.multiframeID=MFD.multiframeID and M.filterID=5 
and skyNoise>-0.9e9 and seeing>0.0 and MFD.deprecated=0 and M.deprecated=0 
and M.multiframeID=T.multiframeID

