w******n 发帖数: 15 | 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??? | b****e 发帖数: 1275 | 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???
| w******n 发帖数: 15 | 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);
| b****e 发帖数: 1275 | 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???
| f*****c 发帖数: 22 | 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. |
|