1

请参考此页面: http ://allblacks.01dev.co.nz/templates/super14/textobjects/SRMatchDayList.cfm 查询转储包含在那里。我继承了这段代码,如果可能的话,我更愿意使用它。

以下代码按周输出固定装置。

<table cellspacing="0" cellpadding="0" border="0" align="center" width="530">
    <tr bgcolor="#797979">
        <th align="left"><p>&nbsp;<b>Date</b></p></td>
        <th align="left"><p><b>Game</b></p></td>
        <th align="left"><p><b>Venue</b></p></td>
        <th align="left"><p><b>Time (NZ)</b></p></td>
        <th align="center"><p><b>Result</b>&nbsp;</p></td>
    </tr>

    <cfset iWeekCounter = 0>
    <cfif not attributes.useSegmentTitle and attributes.sortDirection is "desc">
        <cfset qSegments = oSeries.getSegmentInfo(seriesID=attributes.seriesID)>
        <cfset iWeekCounter = qSegments.recordcount + 1>
    </cfif>

    <cfoutput query="qSeriesEvents" group="segmentID">
        <cfif attributes.sortDirection is "desc">
            <cfset iWeekCounter = iWeekCounter-1>
        <cfelse>
            <cfset iWeekCounter = iWeekCounter+1>
        </cfif>
        <tr>
            <td colspan="5"><p><br><strong>
                <cfif attributes.useSegmentTitle>
                    #qSeriesEvents.segment#
                <cfelse>
                    Week #iWeekCounter#
                </cfif>
            </strong></p></td>
        </tr>
        <cfoutput>
            <cfif textObjectCount gt 0>
                <tr>
                    <td><p>&nbsp;#DateFormat(eventDateTime, "dd mmm")#</p></td>
                    <td><p><a href="/index.cfm?layout=#attributes.eventLayout#&event=#eventID#">#event#</a></p></td>
                    <td><p>#location#</p></td>
                    <td><p><cfif showTimeField is 1>#lcase(timeFormat(dateadd('h',iTimeOffset,eventDateTime),"h:mm tt"))#</cfif></p></td>
                    <td align="center" valign="top"><p><cfif isDate(eventDateTime) AND dateDiff("n",eventDateTime, now())>#oEvent.getTeamResult(eventID, homeTeamID)#-#oEvent.getTeamResult(eventID, awayTeamID)#</cfif>&nbsp;</p></td>
                </tr>
                <tr><td colspan="5"><div style="height:1px; padding:0px; margin0px; font-size:0; border-bottom: 1px solid ##999"></div></td></tr>
            </cfif>
        </cfoutput>
    </cfoutput>
</table>

但是,请注意上述 URL 中的第 3 - 18 周,它们没有任何数据。如果没有数据,我不想显示周线。如果可能,如何使用此查询输出“group =”设置来完成此操作?

来自网站的 SQL

SELECT tObj.textObjectCount, events.*, venues.venue, venues.location, DATENAME(wk, events.eventDateTime - 1) AS EventWeek, s.segment 
FROM events join segments s on s.segmentID = events.segmentID 
 LEFT OUTER JOIN (
  SELECT LUTextObjectEvent.eventID, COUNT(*) AS textObjectCount 
  FROM  LUTextObjectEvent 
   INNER JOIN textObjects ON LUTextObjectEvent.textObjectID = textObjects.textObjectID 
   GROUP BY LUTextObjectEvent.eventID
  ) tObj 
  ON events.eventID = tObj.eventID 
 LEFT OUTER JOIN venues ON events.venueID = venues.venueID 
WHERE (events.eventID IN (
 SELECT eventID 
 FROM events
 WHERE segmentID IN (
  SELECT segmentID 
  FROM segments 
  WHERE seriesID IN (?))
 )
) 
ORDER BY s.segmentID asc
4

1 回答 1

2

您正在使用 a LEFT OUTER JOIN,这意味着您将为每个事件/片段创建一个记录。将它们更改为内部连接,您应该会得到想要的结果

SELECT tObj.textObjectCount, events.*, venues.venue, venues.location, DATENAME(wk, events.eventDateTime - 1) AS EventWeek, s.segment 
FROM events join segments s on s.segmentID = events.segmentID 
 INNER JOIN (
  SELECT LUTextObjectEvent.eventID, COUNT(*) AS textObjectCount 
  FROM  LUTextObjectEvent 
   INNER JOIN textObjects ON LUTextObjectEvent.textObjectID = textObjects.textObjectID 
   GROUP BY LUTextObjectEvent.eventID
  ) tObj 
  ON events.eventID = tObj.eventID 
 INNER JOIN JOIN venues ON events.venueID = venues.venueID 
WHERE (events.eventID IN (
 SELECT eventID 
 FROM events
 WHERE segmentID IN (
  SELECT segmentID 
  FROM segments 
  WHERE seriesID IN (?)))) 
ORDER BY s.segmentID asc
于 2013-02-17T15:45:06.237 回答