Sql 语句将行减半

发布于 2024-12-07 22:32:43 字数 892 浏览 3 评论 0原文

这是我当前的 sql 查询,

        SELECT 
    w.city, t.tmc, t.date, t.time, w.event, 
    ROUND(AVG(w.Pave), 0) surface_temperature, 
    ROUND(AVG(w.Air), 0) air_temperature, 
    ROUND(AVG(a.material_rate),0) material_rate, 
    w.intensity, t.avg 
    FROM winter2010.traffictest t 
    LEFT OUTER JOIN winter2010.application a ON a.DATE = t.DATE AND a.tmc = t.tmc AND a.tmc = t.tmc AND Left(a.time,2) = Left(t.time, 2) 
    LEFT OUTER JOIN winter2010.weather w ON t.DATE = w.DATE AND t.tmc = w.tmc AND  Left(t.time, 2) =  Left(w.time, 2) 
    GROUP BY tmc, t.time 
    INTO OUTFILE 'c:/sass2.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES 
TERMINATED BY '\n';

我正在从以下 sql 语句创建此 csv 文件,它工作得很好,除了一件事,它只占用 1/2 行!

TrafficTest一共有2661行 当我将数据导出到 csv 时,它只输入 1331。

我更改了流量测试的大小,这也是正确的,除非我只有 3 行,它实际上拉出了所有三行。

任何帮助解决这个问题的帮助将不胜感激。

Here is my current sql query

        SELECT 
    w.city, t.tmc, t.date, t.time, w.event, 
    ROUND(AVG(w.Pave), 0) surface_temperature, 
    ROUND(AVG(w.Air), 0) air_temperature, 
    ROUND(AVG(a.material_rate),0) material_rate, 
    w.intensity, t.avg 
    FROM winter2010.traffictest t 
    LEFT OUTER JOIN winter2010.application a ON a.DATE = t.DATE AND a.tmc = t.tmc AND a.tmc = t.tmc AND Left(a.time,2) = Left(t.time, 2) 
    LEFT OUTER JOIN winter2010.weather w ON t.DATE = w.DATE AND t.tmc = w.tmc AND  Left(t.time, 2) =  Left(w.time, 2) 
    GROUP BY tmc, t.time 
    INTO OUTFILE 'c:/sass2.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES 
TERMINATED BY '\n';

I'm creating this csv file from the following sql statement and it works great except for one thing, its only taking 1/2 the rows!

There are a total of 2661 rows in traffictest
And when I outfile the data into the csv its only putting 1331.

I've changed the size of traffictest and this holds true except when I had only 3 rows it actually pulled all three rows.

Any help figuring this out would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

难忘№最初的完美 2024-12-14 22:32:43

当您使用 GROUP BY 时,MySql 每组仅返回一行,您有具有相似 tmc-time 的行,并且 MySql 对于所有此类行仅返回一行,这就是行数减少的原因。

When you use GROUP BY MySql returns only one row per group, You have rows with similar tmc-time and MySql is returning only one row for all such rows that's the reason for decrease in row number.

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