我有三个表:数据,网络和软件。数据表具有我所有客户的名称,而网络和软件表具有服务票据。我们需要每个客户每月至少从两张表(网络或软件)中选择一张票。我需要一个查询来计算每个月的数据表中每个客户端的两张表(网络和软件)的票数。将两个表中的行关联到第三个表中
欲望结果: Final query
我发现与此查询计数的方式,但我不知道如何从两个表计数。
SELECT institucion
,(SELECT count(institucion) FROM network WHERE data.institucion = network.institucion and fecha like '2016-07%')as July
,(SELECT count(institucion) FROM network WHERE data.institucion = network.institucion and fecha like '2016-08%')as August
,(SELECT count(institucion) FROM network WHERE data.institucion = network.institucion and fecha like '2016-09%')as September
,(SELECT count(institucion) FROM network WHERE data.institucion = network.institucion and fecha like '2016-10%')as October
,(SELECT count(institucion) FROM network WHERE data.institucion = network.institucion and fecha like '2016-11%')as November
,(SELECT count(institucion) FROM network WHERE data.institucion = network.institucion and fecha like '2016-12%')as December
,(SELECT count(institucion) FROM network WHERE data.institucion = network.institucion and fecha like '2017-01%')as January
,(SELECT count(institucion) FROM network WHERE data.institucion = network.institucion and fecha like '2017-02%')as February
,(SELECT count(institucion) FROM network WHERE data.institucion = network.institucion and fecha like '2017-03%')as March
,(SELECT count(institucion) FROM network WHERE data.institucion = network.institucion and fecha like '2017-04%')as April
,(SELECT count(institucion) FROM network WHERE data.institucion = network.institucion and fecha like '2017-05%')as May
,(SELECT count(institucion) FROM network WHERE data.institucion = network.institucion and fecha like '2017-06%')as June
FROM data
where data.erate = 'y'
order by institucion