我在mysql中有两个表。第一个表的名称包含以下日期:
我还有其他的表别名。
我需要一个视图,包含名称、别名、号码和价格。 但是我需要在名称上进行左外连接以获取所有行。 问题在于,当查询为“othercarlos”时,我需要价格为卡洛斯服务的平均价格;当查询为“other”时,我需要出现所有服务的平均价格。但是它会显示null。 http://sqlfiddle.com/#!2/c1d4f/1 我创建了这些表和我的查询。
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”时,我需要价格为卡洛斯服务的平均价格;当查询为“other”时,我需要出现所有服务的平均价格。但是它会显示null。 http://sqlfiddle.com/#!2/c1d4f/1 我创建了这些表和我的查询。