我已经为此花了一段时间,现在我觉得事情已经太复杂了。我所拥有的是包含字段的表
我需要把它变成
对于任何给定的日期,当天可能没有打开或关闭任何问题。该天仍应包含0's
我采用了多种方法,可以一次产生一个期望的结果(打开,关闭,结束时打开),但是我无法一次全部获得它们,至少不能成倍地增加增加查询时间。
我当前作为视图的查询如下
打开
select Cast(EntryDateTime as Date) as DateStamp
,ContractNumber
,Client
,services.Service
,sum(1) as Count
,lag(sum(1)) OVER (
partition by tickets.ContractNumber
,services.Service ORDER BY Cast(EntryDateTime as Date) ASC
) as CountDayBefore
from v_JiraImpactedServices as services
LEFT JOIN v_JiraTickets as tickets ON services.ticketnumber = tickets.TicketNumber
WHERE tickets.Client is not null
AND tickets.TicketNumber IS NOT NULL
and tickets.ContractNumber is not null
GROUP BY Cast(tickets.EntryDateTime as Date)
,tickets.ContractNumber
,tickets.Client
,services.Service;
关闭日期
select Cast(ResolvedDateTime as Date) as DateStamp
,ContractNumber
,Client
,services.Service
,sum(1) as Count
,lag(sum(1)) OVER (
partition by tickets.ContractNumber
,services.Service ORDER BY Cast(ResolvedDateTime as Date) ASC
) as CountDayBefore
from v_JiraImpactedServices as services
LEFT JOIN v_JiraTickets as tickets ON services.ticketnumber = tickets.TicketNumber
WHERE tickets.Client is not null
and tickets.TicketNumber is not null
AND tickets.ContractNumber is not null
GROUP BY Cast(tickets.ResolvedDateTime as Date)
,tickets.ContractNumber
,tickets.Client
,services.Service;
打开
SELECT calendar.FullDate as DateStamp
,tickets.ContractNumber
,tickets.client
,services.Service
,IsNull(count(tickets.TicketNumber), 0) as Count
,IsNull(lag(count(tickets.TicketNumber), 1) OVER (
partition by tickets.ContractNumber
,services.Service Order By FullDate ASC
), 0) as CountDayBefore
FROM v_Calendar as calendar
LEFT JOIN v_JiraTickets as tickets ON Cast(tickets.EntryDateTime as Date) <= calendar.FullDate
AND (
Cast(tickets.ResolvedDateTime as Date) > calendar.FullDate
OR tickets.ResolvedDateTime is null
)
LEFT JOIN v_JiraImpactedServices as services ON services.ticketnumber = tickets.TicketNumber
WHERE tickets.Client is not null
AND tickets.ContractNumber is not null
GROUP BY calendar.FullDate
,tickets.ContractNumber
,tickets.Client
,services.Service;
正如我所说的那样,它们本身都能给ALMOST带来理想的结果,但是省略了0值的日子。
除了生成具有0个值的天数外,我还需要将这些值合并为一个表结果。到目前为止,所有尝试要么产生明显错误的JOIN结果,要么执行一个小时。
如果有人能指出我正确的方向,我将不胜感激。
答案 0 :(得分:0)
只是给您一个想法,尽管字段名称与您的情况不符,但这是我的处理方式:
apply plugin: 'com.android.application'
android {
buildToolsVersion '28.0.2'
compileSdkVersion 28
dexOptions {
javaMaxHeapSize "4g"
}
defaultConfig {
applicationId "xxxxxxxxxxxxxxxxxx"
minSdkVersion 15
targetSdkVersion 28
// Enabling multidex support.
multiDexEnabled true
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
androidTest.setRoot('tests')
}
}
repositories {
mavenCentral()
google()
jcenter()
}
dependencies {
api project(':BaseGameUtils')
api files('libs/AudienceNetwork.jar')
api files('libs/FacebookAdapter.jar')
implementation files('libs/chartboost.jar')
implementation files('libs/chartboost-7.2.0.1.aar')
api 'com.android.support:multidex:1.0.3'
api 'com.facebook.android:facebook-android-sdk:4.36.1'
api 'com.google.firebase:firebase-core:16.0.1'
api 'com.google.firebase:firebase-analytics:16.0.1'
api 'com.google.firebase:firebase-invites:16.0.1'
api 'com.google.firebase:firebase-ads:15.0.1'
api 'com.google.firebase:firebase-messaging:17.1.0'
api 'com.google.firebase:firebase-appindexing:16.0.1'
api 'com.google.android.gms:play-services-analytics:16.0.1'
api 'com.google.android.gms:play-services-games:15.0.1'
api 'com.google.android.gms:play-services-identity:15.0.1'
api 'com.google.android.gms:play-services-plus:15.0.1'
}