Sample SQLs

Sample 1   Sample 2   Sample 3   Sample 4  


SELECT   obj.run,
         Str(obj.psfmag_z - 0 * obj.extinction_z,6,3) AS z,
         Str(60 * distance,3,1) AS d,
         dbo.Ffield(neighborobjid) AS nfield,
         Str(dbo.Fobj(neighborobjid),4) AS nid,
         'new' AS 'new'
FROM     (SELECT obj.objid,
                 extinction_z,
                 nn.neighborobjid,
                 nn.distance
          FROM   photoobj AS obj
                 JOIN neighbors AS nn
                   ON obj.objid = nn.objid
          WHERE  60 * nn.distance BETWEEN 0
                                          AND 15
                 AND nn.mode = 1
                 AND nn.neighbormode = 1
                 AND run = 756
                 AND camcol = 5
                 AND obj.TYPE = 6
                 AND (obj.flags & 0x40006) = 0
                 AND nchild = 0
                 AND obj.psfmag_i < 20
                 AND (g - r BETWEEN 0.3
                                    AND 1.1
                      AND r - i BETWEEN -0.1
                                        AND 0.6)) AS obj
         JOIN photoobj AS nobj
           ON nobj.objid = obj.neighborobjid
WHERE    nobj.run = obj.run
         AND (Abs(obj.psfmag_g - nobj.psfmag_g) < 0.5
               OR Abs(obj.psfmag_r - nobj.psfmag_r) < 0.5
               OR Abs(obj.psfmag_i - nobj.psfmag_i) < 0.5)
ORDER BY obj.run,
         obj.camcol,
         obj.field

SQL before beautify

select 
obj.run, obj.camCol, str(obj.field, 3) as field, 
str(obj.psfMag_z - 0*obj.extinction_z, 6, 3) as z, 
str(60*distance, 3, 1) as D, 
dbo.fField(neighborObjId) as nfield, 
str(dbo.fObj(neighborObjId), 4) as nid,'new' as 'new' 
from 
(select obj.objId, 
psfMag_z, extinction_z, 
NN.neighborObjId, NN.distance 
from photoObj as obj 
join neighbors as NN on obj.objId = NN.objId 
where 
60*NN.distance between 0 and 15 and 
NN.mode = 1 and NN.neighborMode = 1 and 
run = 756 and camCol = 5 and 
obj.type = 6 and (obj.flags & 0x40006) = 0 and 
nchild = 0 and obj.psfMag_i < 20 and 
(g - r between 0.3 and 1.1 and r - i between -0.1 and 0.6) 
) as obj 
join photoObj as nobj on nobj.objId = obj.neighborObjId 
where 
nobj.run = obj.run and 
(abs(obj.psfMag_g - nobj.psfMag_g) < 0.5 or 
abs(obj.psfMag_r - nobj.psfMag_r) < 0.5 or 
abs(obj.psfMag_i - nobj.psfMag_i) < 0.5) 
order by obj.run, obj.camCol, obj.field