------------------------------------------------------------------------
Querying Gaia database: Star density at the North Ecliptic pole
------------------------------------------------------------------------
TESS, SRG, WISE survey the ecliptic poles for every rotation of the
satellite orbit. ULTRASAT will stare at the ecliptic poles (during
summer and winter, successively). I wanted to know the Gaia stellar
density of the ecliptic poles. To be concrete, we wish to extract
stars within 5 degrees (radius) of the North Ecliptic Pole (NEP).
This corresponds to a solid angle of 4*pi*(1-cosd(5)) where "cosd"
is the cosine(theta) but theta is in degrees or 
Omega=156.98 square degrees.


https://gea.esac.esa.int/archive/

Select "Search"

Choose "Equatorial" and set RA=18 0 0, Dec=+66 33 38.55 (NEP)
Choose "Circle" and  set Radius=5 deg

"Show Query" and you will see in the query box
================================================================================
SELECT TOP 500 
gaia_source.source_id,gaia_source.ra,gaia_source.ra_error,gaia_source.dec,gaia_source.dec_error,gaia_source.parallax,gaia_source.parallax_error,gaia_source.phot_g_mean_mag,gaia_source.bp_rp,gaia_source.radial_velocity,gaia_source.radial_velocity_error,gaia_source.phot_variable_flag,gaia_source.teff_val,gaia_source.a_g_val
FROM gaiadr2.gaia_source 
WHERE 
CONTAINS(
	POINT('ICRS',gaiadr2.gaia_source.ra,gaiadr2.gaia_source.dec),
	CIRCLE('ICRS',270,66.56070833333332,5)
)=1
================================================================================

Your query is translated to SQL. As it now stands, "SELECT TOP 500"
restricts the number of output records.  Delete "TOP 500"  in the
box and then "Submit Query".  Wait for the job to finish.

I will assume that you have chosen "csv" format for the output.
Retrieve the data file.  Rename file to, say, "gaia.csv".

	#which column is what
$ head -1 gaia.dat | tr ',' '\n' | nl
     1	source_id
     2	ra
     3	ra_error
     4	dec
     5	dec_error
     6	parallax
     7	parallax_error
     8	phot_g_mean_mag
     9	bp_rp
    10	radial_velocity
    11	radial_velocity_error
    12	phot_variable_flag
    13	teff_val
    14	a_g_val

	#how many objects?
	#Note subtlety in how I avoided the file name in the output of wc
$ echo "total number of objects:" $(wc -l < gaia.csv)

	#we now histogram the data and produce cumulative counts
	#
$ sed '1d' gaia.csv | awk -F, '{print int($8)}' | sort -n | uniq -c | \
	awk '{n+=$1;print $2,n,(n/157)*47}'
4 4 1.19745
5 6 1.79618
6 31 9.28025
7 109 32.6306
8 323 96.6943
9 801 239.79
10 1935 579.268
11 4268 1277.68
12 9065 2713.73
13 18677 5591.2
14 36718 10992
15 67682 20261.5
16 115160 34474.6
17 183086 54809.2
18 277505 83074.7
19 410230 122808
20 591503 177074
21 612577 183383

The first column is mag, the second column is the cumulative areal
density (objects/sq. deg) and the last column is the cumulative
number of stars in a ZTF pointing (47 sq. deg).