
{\fam \bffam \tenssbxsmall (7.1)}

\startverbatim
SELECT TOP 20
source_id, phot_g_mean_mag
FROM gaiadr1.tgas_source
ORDER BY phot_g_mean_mag
|endverbatim

{\fam \bffam \tenssbxsmall (8.1)}

\startverbatim
SELECT TOP 20
source_id, ra, dec,
SQRT(POWER(pmra,2)+POWER(pmdec,2))/1000 AS pmtot,
phot_g_mean_mag
FROM gaiadr1.tgas_source
ORDER BY pmtot DESC
|endverbatim

{\fam \bffam \tenssbxsmall (9.1)}

The right solution would look like:
\startverbatim
SELECT TOP 20 source_id, ra, dec, phot_g_mean_mag,
5+5*log10(parallax/1000)+phot_g_mean_mag as absmag
FROM gaiadr1.tgas_source
WHERE parallax > 1
ORDER BY phot_g_mean_mag DESC
|endverbatim
Notice, that the WHERE clause is necessary because the log of a negativ
number must fail.

{\fam \bffam \tenssbxsmall (10.1)}

\startverbatim
SELECT
  ROUND(phot_g_mean_mag) AS bin,
  COUNT(*) AS n,
  AVG(SQRT(POWER(pmra,2)+POWER(pmdec,2))) AS pmavg
FROM gaiadr1.tgas_source
GROUP BY bin
ORDER BY bin


|endverbatim

{\fam \bffam \tenssbxsmall (13.1)}

\startverbatim
SELECT TOP 5000 hipp.hip, id,
 SQRT(POWER(hipp.pmra,2)+POWER(hipp.pmdec,2))/1000 AS pmtothip,
 SQRT(POWER(t2.pmra,2)+POWER(t2.pmde,2))/1000 AS pmtott2
FROM hipparcos as hipp
JOIN tycho2 AS t2 ON (
  1=CONTAINS(
    POINT('ICRS', hipp.ra, hipp.dec),
    CIRCLE('ICRS', t2.ra, t2.dec, 0.001)))
|endverbatim
