1

これが私のクエリですsql server

SELECT     dbo.tbScheduleDetail.CareProfessionalIDF, 
                dbo.tbScheduleDetail.CareProviderIDF,
                dbo.tbCareProvider.CareProviderName, 
                dbo.tbCitizen.FirstName + ' ' + dbo.tbCitizen.MiddleName + ' ' + dbo.tbCitizen.FamilyName AS CareProfessionalName,  
                dbo.tbScheduleTimeSlot.ScheeduleWeekDays, 
                dbo.tbScheduleTimeSlot.ScheduleStartTime, dbo.tbScheduleTimeSlot.ScheduleEndTime, 

                    dbo.tbScheduleDetail.ScheduleStartDate, dbo.tbScheduleDetail.ScheduleEndDate          
FROM         dbo.tbScheduleTimeSlot INNER JOIN
                      dbo.tbScheduleDetail ON dbo.tbScheduleTimeSlot.ScheduleDetailIDF = dbo.tbScheduleDetail.ScheduleDetailIDP INNER JOIN
                      dbo.tbCareProvider ON dbo.tbScheduleDetail.CareProviderIDF = dbo.tbCareProvider.CareProviderIDP INNER JOIN
                      dbo.tbCareProfessional ON dbo.tbScheduleDetail.CareProfessionalIDF = dbo.tbCareProfessional.CareProfessionalIDP INNER JOIN
                      dbo.tbCitizen ON dbo.tbCareProfessional.CitizenIDF = dbo.tbCitizen.CitizenIDP
WHERE     (dbo.tbScheduleDetail.IsActive = 1) and CareProviderIDF=4 order by CareProfessionalIDF

出力:

ここに画像の説明を入力

最後に私は好きになりたい

そのため、そのインデックスについて、ストラトタイムとエンドタイムを保存したいので、「、」でスケジュールウィークデイズを分割しました。day[index]

ここでは、組み合わせ (CareProfessionalIDF=11) の 1 つだけを使用します。

====================================
         StartTime TO EndTime    
====================================
 day[0] = 00:00TO22:00
 day[1] = 00:00TO22:00
 day[2] = 04:15TO19:15
 day[3] = 04:00TO20:00 
 day[4] = 08:00TO15:00
 day[5] = ""
 day[6] = ""

では、すべての組み合わせに対してこのようなデータを保存するにはどうすればよいですか。data structure私が使用しなければならないことのために?

4

4 に答える 4

1

このようなことを試してください -

SELECT  sd.CareProfessionalIDF
    ,   CareProviderIDF = MAX(sd.CareProviderIDF)
    ,   ScheeduleWeekDays = MAX(sts.ScheeduleWeekDays)
    ,   ScheduleTimeSlotIDP = MAX(sts.ScheduleTimeSlotIDP)
    ,   ScheduleStartTime = MAX(sts.ScheduleStartTime)
    ,   ScheduleEndTime = MAX(sts.ScheduleEndTime)
    ,   CareProviderName = MAX(cp.CareProviderName)
    ,   CareProfessionalName = MAX(c.FirstName + ' ' + c.MiddleName + ' ' + c.FamilyName)
    ,   ScheduleFor = MAX(sd.ScheduleFor)
    ,   ScheduleStartDate = MAX(sd.ScheduleStartDate)
    ,   ScheduleEndDate = MAX(sd.ScheduleEndDate)
    ,   SplitIntervalStart = MAX(sts.SplitIntervalStart)
    ,   SplitIntervalEnd = MAX(sts.SplitIntervalEnd)
    ,   SlotInterval = MAX(sts.SlotInterval)
    ,   IsActive = MAX(sd.IsActive)
    ,   IsSplitSchedule = MAX(sts.IsSplitSchedule)
FROM dbo.tbScheduleTimeSlot sts
JOIN dbo.tbScheduleDetail sd ON sts.ScheduleDetailIDF = sd.ScheduleDetailIDP
JOIN dbo.tbCareProvider cp ON sd.CareProviderIDF = cp.CareProviderIDP
JOIN dbo.tbCareProfessional cp2 ON sd.CareProfessionalIDF = cp2.CareProfessionalIDP
JOIN dbo.tbCitizen c ON cp2.CitizenIDF = c.CitizenIDP
WHERE sts.IsActive = 1
    AND CareProviderIDF = 4
GROUP BY sd.CareProfessionalIDF
于 2013-09-09T09:43:08.403 に答える
1

どうですか

Select Sum(CareProfessionalIDF) as CareProfessionalID ,...... from {
-- Your query

} group by CareProfessionalIDF ,......
于 2013-09-09T09:26:15.243 に答える
1

を使用する場合、選択したすべての列を Group By 句に含めるGroub byか、残りの列を含める必要があります。aggregate

集計によるクエリ

SELECT  FieldToGroup ,
        SUM(FieldToSum)
FROM    TableName
GROUP BY FieldToGroup

すべてのフィールドがグループ化されたクエリ

SELECT  FieldToGroup ,
        Field2ToGroup
FROM    TableName
GROUP BY FieldToGroup ,
        Field2ToGroup
于 2013-09-09T09:11:25.053 に答える
0

これを試してみてください...

SELECT  dbo.tbScheduleDetail.CareProfessionalIDF ,
        dbo.tbScheduleDetail.CareProviderIDF ,
        dbo.tbScheduleTimeSlot.ScheeduleWeekDays ,
        dbo.tbScheduleTimeSlot.ScheduleTimeSlotIDP ,
        dbo.tbScheduleTimeSlot.ScheduleStartTime ,
        dbo.tbScheduleTimeSlot.ScheduleEndTime ,
        dbo.tbCareProvider.CareProviderName ,
        dbo.tbCitizen.FirstName + ' ' + dbo.tbCitizen.MiddleName + ' '
        + dbo.tbCitizen.FamilyName AS CareProfessionalName ,
        dbo.tbScheduleDetail.ScheduleFor ,
        dbo.tbScheduleDetail.ScheduleStartDate ,
        dbo.tbScheduleDetail.ScheduleEndDate ,
        dbo.tbScheduleTimeSlot.SplitIntervalStart ,
        dbo.tbScheduleTimeSlot.SplitIntervalEnd ,
        dbo.tbScheduleTimeSlot.SlotInterval ,
        dbo.tbScheduleDetail.IsActive ,
        dbo.tbScheduleTimeSlot.IsSplitSchedule
FROM    dbo.tbScheduleTimeSlot
        INNER JOIN dbo.tbScheduleDetail ON dbo.tbScheduleTimeSlot.ScheduleDetailIDF = dbo.tbScheduleDetail.ScheduleDetailIDP
        INNER JOIN dbo.tbCareProvider ON dbo.tbScheduleDetail.CareProviderIDF = dbo.tbCareProvider.CareProviderIDP
        INNER JOIN dbo.tbCareProfessional ON dbo.tbScheduleDetail.CareProfessionalIDF = dbo.tbCareProfessional.CareProfessionalIDP
        INNER JOIN dbo.tbCitizen ON dbo.tbCareProfessional.CitizenIDF = dbo.tbCitizen.CitizenIDP
WHERE   ( dbo.tbScheduleTimeSlot.IsActive = 1 )
        AND CareProviderIDF = 4 ORDER BY dbo.tbScheduleDetail.CareProfessionalIDF
于 2013-09-09T09:51:41.613 に答える