需要帮助为每个 group_concat() 项生成 span 标记。 mysql、VB.Net

发布于 2024-12-02 02:04:26 字数 2319 浏览 1 评论 0原文

我目前有一个 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")%>&deg;</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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稀香 2024-12-09 02:04:26

这是你想要的吗?

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

您想要区分的所有字段都放在 group by 部分中。
所有未由 group by 唯一定义的值都会进入 group_concat

您将需要编辑此行:

 , group_concat(CONCAT(... 

稍微修改一下以使其正确,请参阅:
http://dev.mysql.com /doc/refman/5.0/en/group-by-functions.html#function_group-concat

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文