Join results from two queries

153 views
Skip to first unread message

Moisés Belchín

unread,
Apr 25, 2012, 12:09:36 PM4/25/12
to bigquery...@googlegroups.com
Hi all,

I want to get two differents results from the same table, I mean:

SELECT count(*) as Lec FROM my_table WHERE fecha_lec < '2012-04-24';
SELECT count(*) as Rec FROM my_table WHERE fecha_rec < '2012-04-24';


I would like to join both results and launch only one query, is it possible?

Thanks so much.

Siddartha Naidu

unread,
Apr 25, 2012, 12:58:09 PM4/25/12
to bigquery...@googlegroups.com
This should be possible using this simple scheme:

SELECT
  SUM(IF(fecha_lec < '...', 1, 0)) as Lec,
  SUM(IF(fecha_rec < '...', 1, 0)) as Rec
FROM my_table;

Moises Belchin

unread,
Apr 26, 2012, 4:03:49 AM4/26/12
to bigquery...@googlegroups.com
Very clear and useful answer.

Thanks and best regards

Saludos.
Moisés Belchín.



2012/4/25 Siddartha Naidu <sna...@google.com>
Reply all
Reply to author
Forward
0 new messages