需要帮助为每个 group_concat() 项生成 span 标记。 mysql、VB.Net
我目前有一个 sql select 语句,它从 3 个不同的表中选择几个内容,代码如下:
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
我正在使用以下中继器将其显示在地图上:
<asp:Repeater id="weatherFeed" Runat="server"><ItemTemplate>
<a href="index.htm" onClick="return hs.htmlExpand(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")%>°</div><div
class="span-1"><%#Container.DataItem("times")%></div>
</div>
</ItemTemplate></asp:Repeater>
我遇到的问题是,我想要适合各种温度和每次生产。目前,它将所有温度放在 1 div 中,并且所有时间都放在 1 div 中,这是因为我正在使用 group_concat()。如果我从时间/表面温度中删除 group_concat() ,那么我只会得到包含基于我的 select 语句的数据的第一行。我怎样才能调整我的sql语句,以便我可以产生以下结果:
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>
非常感谢!
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.htmlExpand(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")%>°</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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是你想要的吗?
您想要区分的所有字段都放在
group by
部分中。所有未由
group by
唯一定义的值都会进入group_concat
您将需要编辑此行:
稍微修改一下以使其正确,请参阅:
http://dev.mysql.com /doc/refman/5.0/en/group-by-functions.html#function_group-concat
Is this what you want?
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 agroup_concat
You will need to edit this line:
a bit to get things right, see:
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat