以下是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
输出:
最后我想要像
一样所以我用','比我得到的那样分配了scheduleweekdays,对于那个索引,我想在day[index]
中存储strattime和endtime
这里我只采用其中一种组合 (CareProfessionalIDF = 11)我有4行和存储时间
====================================
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
我必须使用的那个?
答案 0 :(得分:1)
当您使用Groub by
时,您需要包含您在Group By Clause中选择的所有列,或者您需要aggregate
其余列,例如< / p>
使用聚合查询
SELECT FieldToGroup ,
SUM(FieldToSum)
FROM TableName
GROUP BY FieldToGroup
查询所有字段分组
SELECT FieldToGroup ,
Field2ToGroup
FROM TableName
GROUP BY FieldToGroup ,
Field2ToGroup
答案 1 :(得分:1)
怎么样
Select Sum(CareProfessionalIDF) as CareProfessionalID ,...... from {
-- Your query
} group by CareProfessionalIDF ,......
答案 2 :(得分: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
答案 3 :(得分: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