无法摆脱重复
Can't get rid of duplicates
我有我的疑问:
SELECT t.nCitiesId
,t.tmDate
,t.strShortWeekdayName
,t.nIsHoliday
FROM #temp AS t
WHERE 1 = 1
AND t.nCitiesId = 104
AND t.tmDate = '2014-06-08'
GROUP BY t.tmDate, t.nCitiesId, t.strShortWeekdayName, t.nIsHoliday
这会生成以下结果:
nCitiesId tmDate strShortWeekdayName nIsHoliday
104 2014-06-08 00:00:00.000 SUN 0
104 2014-06-08 00:00:00.000 SUN 1
我的问题是当 nCitiesId 和 tmDate 相等时,我不希望 nIsHoliday = 0 的那个消失。
我怎样才能顺利地做到这一点?
尝试使用 having 子句:
SELECT t.nCitiesId
,t.tmDate
,t.strShortWeekdayName
,t.nIsHoliday
FROM #temp AS t
WHERE 1 = 1
AND t.nCitiesId = 104
AND t.tmDate = '2014-06-08'
GROUP BY t.tmDate, t.nCitiesId, t.strShortWeekdayName, t.nIsHoliday
having max(t.nIsHoliday)
选择具有最高价值的t.nIsHoliday:
SELECT t.nCitiesId
,t.tmDate
,t.strShortWeekdayName
,max(t.nIsHoliday)
FROM #temp AS t
WHERE t.nCitiesId = 104
AND t.tmDate = '2014-06-08'
GROUP BY t.nCitiesId, t.tmDate, t.strShortWeekdayName
我有我的疑问:
SELECT t.nCitiesId
,t.tmDate
,t.strShortWeekdayName
,t.nIsHoliday
FROM #temp AS t
WHERE 1 = 1
AND t.nCitiesId = 104
AND t.tmDate = '2014-06-08'
GROUP BY t.tmDate, t.nCitiesId, t.strShortWeekdayName, t.nIsHoliday
这会生成以下结果:
nCitiesId tmDate strShortWeekdayName nIsHoliday
104 2014-06-08 00:00:00.000 SUN 0
104 2014-06-08 00:00:00.000 SUN 1
我的问题是当 nCitiesId 和 tmDate 相等时,我不希望 nIsHoliday = 0 的那个消失。
我怎样才能顺利地做到这一点?
尝试使用 having 子句:
SELECT t.nCitiesId
,t.tmDate
,t.strShortWeekdayName
,t.nIsHoliday
FROM #temp AS t
WHERE 1 = 1
AND t.nCitiesId = 104
AND t.tmDate = '2014-06-08'
GROUP BY t.tmDate, t.nCitiesId, t.strShortWeekdayName, t.nIsHoliday
having max(t.nIsHoliday)
选择具有最高价值的t.nIsHoliday:
SELECT t.nCitiesId
,t.tmDate
,t.strShortWeekdayName
,max(t.nIsHoliday)
FROM #temp AS t
WHERE t.nCitiesId = 104
AND t.tmDate = '2014-06-08'
GROUP BY t.nCitiesId, t.tmDate, t.strShortWeekdayName