using a common key value on both sides of a union ?

Поиск
Список
Период
Сортировка
От David Gauthier
Тема using a common key value on both sides of a union ?
Дата
Msg-id CAMBRECA1wcBakFr=jLusdUYd9g1d70TNM_oPxWhmiw9OV=RXOw@mail.gmail.com
обсуждение исходный текст
Ответы Re: using a common key value on both sides of a union ?
Re: using a common key value on both sides of a union ?
Список pgsql-general
psql (9.6.7, server 11.3) on linux

I want to do something like this 
(intentionally bad sql but will illustrate the need)

select s.name,s.grade from students s where s.class='math'
union
select 'whole class', class_grade from all_classes where class=s.class

Of course it's that "where class=s.class" that's a foul.

In English, I want a list of each math student and their grade and then append one more record for the entire class, a record that comes from a different table but narrowed down to that one class.

I don't care if union isn't the right approach.  Anything that works is welcome !

Thanks in Advance 


В списке pgsql-general по дате отправления:

Предыдущее
От: Edson Richter
Дата:
Сообщение: RE: It is possible to force periodically switch xlog?
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: using a common key value on both sides of a union ?