我有一个我想查询的表。查询应该包含两个子查询,因此我认为需要连接操作,但我不确定。我的表看起来像这样:
function getLngLat() {
//stuff
var deferred = $.Deferred();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
//do stuff
deferred.resolve();
} else {
deferred.reject();
}
}
return deferred;
}
我想执行一个查询,以便它首先根据产品交叉制表,然后它会进行另一个查询(在两列,其中Status = Inventory和Date> 7/9/2016),以及将结果加入第一个查询的结果。最后,我想得到以下结果:
Region Product Status Date
Region 1 A Inventory 7/20/2016
Region 2 A Development 7/1/2016
Region 2 B Inventory 7/4/2016
Region 2 B Inventory 7/9/2016
Region 3 B Development 7/8/2016
Region 3 C Inventory 7/15/2016
Region 1 C Development 7/10/2016
为此目的的代码是什么?谢谢
注意:我正在使用Access,我不确定如何将标准Access SQL与其他基于SQL的软件进行比较。
答案 0 :(得分:2)
您可以使用条件聚合执行此操作:
select region,
sum(iif(product = "A", 1, 0)) as A,
sum(iif(product = "B", 1, 0)) as B,
sum(iif(product = "C", 1, 0)) as C,
sum(iif(status = "Inventory" and Date > #7/9/2016#, 1, 0)) as Special
from t
group by region;