avatar
sql high hand please help.# Database - 数据库
w*n
1
say i have three tables, motel, resorts, bed-breakfirst,
and all three tables have a column called price.
and i want to calculate avg, max, and min price
from all three tables. how do i do that?
i know select avg(price) from table-name
but it only gives me avg price from only one table,
how do i get all three tables' avg???
avatar
b*e
2
select avg(price) from
(select price from motel union
select price from resorts union
select price from bed_breakfast);

【在 w******n 的大作中提到】
: say i have three tables, motel, resorts, bed-breakfirst,
: and all three tables have a column called price.
: and i want to calculate avg, max, and min price
: from all three tables. how do i do that?
: i know select avg(price) from table-name
: but it only gives me avg price from only one table,
: how do i get all three tables' avg???

avatar
w*n
3
informix sql says u can't use union inside a sub query.
any other ideas???

【在 b****e 的大作中提到】
: select avg(price) from
: (select price from motel union
: select price from resorts union
: select price from bed_breakfast);

avatar
b*e
4
sorry don't know informix well.. dump informix :)
who still uses it anyway :)

【在 w******n 的大作中提到】
: informix sql says u can't use union inside a sub query.
: any other ideas???

avatar
f*c
5
Use create view that is the union of several tables, and then issue query against
the view?
Don't know whether it works or not in informix. It is ok in MSSql server.
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。