SQL before beautify
select
obj.run, obj.camCol, str(obj.field, 3) as field,
str(obj.rowc, 6, 1) as rowc, str(obj.colc, 6, 1) as colc,
str(dbo.fObj(obj.objId), 4) as id,
str(obj.psfMag_g - 0*obj.extinction_g, 6, 3) as g,
str(obj.psfMag_r - 0*obj.extinction_r, 6, 3) as r,
str(obj.psfMag_i - 0*obj.extinction_i, 6, 3) as i,
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,
run, camCol, field, rowc, colc,
psfMag_u, extinction_u,
psfMag_g, extinction_g,
psfMag_r, extinction_r,
psfMag_i, extinction_i,
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
SQL after beautify
/* Created by free online sql formatter */
SELECT obj.run,
obj.camcol,
Str(obj.field,3) AS field,
Str(obj.rowc,6,1) AS rowc,
Str(obj.colc,6,1) AS colc,
Str(dbo.Fobj(obj.objid),4) AS id,
Str(obj.psfmag_g - 0 * obj.extinction_g,6,3) AS g,
Str(obj.psfmag_r - 0 * obj.extinction_r,6,3) AS r,
Str(obj.psfmag_i - 0 * obj.extinction_i,6,3) AS i,
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,
run,
camcol,
field,
rowc,
colc,
psfmag_u,
extinction_u,
psfmag_g,
extinction_g,
psfmag_r,
extinction_r,
psfmag_i,
extinction_i,
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