【发布时间】:2013-06-02 22:52:50
【问题描述】:
我在 mysql 中有两个表。第一个表是具有以下日期的名称:
name service number
carlos telephone 6
juan watter 12
maria gas 23
jhon hostal 17
marcos sleeping 21
carlos othercarlos 12
other other 13
我还有其他表别名
name service alias price
carlos telephone telephone-carlos 700
carlos sleeping sleeping-carlos 300
juan watter watter-juan 900
maria gas gas-maria 650
jhon hostal hostal-jhon 700
我需要一个包含姓名、别名、号码和王子的视图。 但是我需要名称中的所有行,我打算使用左外连接。 但问题是,当我查询 othercarlos 何时出现时,我需要价格是 carlos 服务的平均值,而当名称为 other 时,我需要显示所有服务的平均值。但显示为空
http://sqlfiddle.com/#!2/c1d4f/1
我创建了这个表和我的查询
【问题讨论】:
-
出色的工作,包括小提琴!我仍然不能完全理解这个问题。你能包括输出吗?
-
你能发布想要的结果吗?