开发者

Need help producing a span tag for every group_concat() item. mySql, VB.Net

开发者 https://www.devze.com 2023-04-01 14:54 出处:网络
I currently have a sql select statement that selects several things from 3 different tables at the moment, here is that code:

I currently have a sql select statement that selects several things from 3 different tables at the moment, here is that code:

SELECT
group_concat(w.event) as events, group_concat(w.date) as dates, 
group_concat(a.time) as times, group_concat(DISTINCT w.tmc) as tmcs, 
group_concat(a.weather) as weathers, group_concat(a.surface_temperature) as temperatures, p.top, p.LEFT, w.City 
FROM weather w 
LEFT OUTER JOIN application a ON a.DATE = w.DATE AND a.tmc = w.tmc 
LEFT OUTER JOIN pinlocations p ON w.city = p.cityname 
WHERE  w.DATE = '" & datepicker_value.Text & "' 
AND w.event= '" & weatherType.SelectedItem.Value & "' GROUP BY p.top, p.left

I'm using the following repeater to display it on a map:

<asp:Repeater id="weatherFeed" Runat="server"><ItemTemplate>
    <a href="index.htm" onClick="return hs.h开发者_运维百科tmlExpand(this)">
    <img src="images/mapPin.png" title="<%#Container.DataItem("city")%>"
        style="position:absolute; left:<%#Container.DataItem("left")%>px; 
        top:<%#Container.DataItem("top")%>px;" /></a>

        <div class="highslide-maincontent">
    Title: <%#Container.DataItem("City")%><br />
        TMC: <%#Container.DataItem("tmcs")%><br />
        Location on the map: <%#Container.DataItem("left")%>, <%#Container.DataItem("top")%><br />
        <div class="span-1">Time</div><div class="span-1">Surface Temperatures</div>
        <div class="span-1"><%#Container.DataItem("temperatures")%>&deg;</div><div 
        class="span-1"><%#Container.DataItem("times")%></div>
        </div> 
</ItemTemplate></asp:Repeater>

The issue I'm having is this, I want the to be produced for every temperature and every time. Currently its putting all the temperatures in 1 div and all the time in 1 div, this is because i'm using group_concat(). If I remove group_concat() from the time/surface temperature then I only get the first row containing data based off my select statement. How can I tweak my sql statement so I can produce the following outcome:

Title: Indianapolis
TMC: 107+4652
Location on the Map: 250, 347
<div class="span-1">Time:</div>    <div class="span-1">Surface Temp:</div> 
<div class="span-1">1:00     <div class="span-1">31deg</div> 
<div class="span-1">2:00     <div class="span-1">36deg</div> 
<div class="span-1">3:00     <div class="span-1">42deg</div>

Greatly Appreciated!


Is this what you want?

SELECT
  p.top, p.LEFT, w.City
  , w.tmc
  , group_concat(w.event) as events
  , group_concat(w.date) as dates
  , group_concat(CONCAT('<div class="span-1">',a.time
                        ,<div class="span-1">, A.surface_temperature)
                 , SEPARATOR '</div>') as divspan
  , group_concat(a.weather) as weathers

FROM weather w 
LEFT JOIN application a ON (a.DATE = w.DATE AND a.tmc = w.tmc) 
LEFT JOIN pinlocations p ON (w.city = p.cityname) 
WHERE w.DATE = '" & datepicker_value.Text & "' 
      AND w.event= '" & weatherType.SelectedItem.Value & "' 
GROUP BY p.top, p.left, w.tmc

All the fields you want to be distinct you put in the group by part.
Al the values not uniquely defined by the group by goes into a group_concat

You will need to edit this line:

 , group_concat(CONCAT(... 

a bit to get things right, see:
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat

0

精彩评论

暂无评论...
验证码 换一张
取 消