简体   繁体   English

select 日名称和最大平均值如何与 sql 的数据库

[英]How select day name and max average with sql's database

I have the following columns in my database: - day - browser - platforms - visitors_number我的数据库中有以下列: - 天 - 浏览器 - 平台 - 访客数

I have to choose the day of the week for which the average number of visitors was maximum and display this maximum average.我必须选择平均访客人数最多的一周中的哪一天,并显示该最大平均值。 I searched the forum, found a similar thread, but the solution does not work, I get an error.我搜索了论坛,找到了一个类似的帖子,但是解决方案不起作用,我得到一个错误。 I would add that I am sitting on it for the second day and I lack ideas.我要补充一点,我已经坐在上面第二天了,我缺乏想法。 I will add that it works on phpMyAdmin.我要补充一点,它适用于 phpMyAdmin。

This is my code:这是我的代码:

    select DAYNAME(DAY), avgVIS
    from 
    (
    select DAYNAME(DAY), avg(VISITORS_NUMBER) as avgVIS
    from dane_2 
    group by DAYNAME(DAY)
    ) 
    where avgVIS = (select max(avgVIS) 
              from ( select DAYNAME(DAY), avg(VISITORS_NUMBER) as avgVIS
              from dane_2 
              group by DAYNAME(DAY)))

this is output's error这是输出的错误

#1064 - Something is wrong in your syntax obok 'where avgVIS = (select max(avgVIS)
              from ( select DAYNAME(DAY), a'

Can someone helps me?有人可以帮助我吗? Thank you in advance先感谢您

You already have the aggregation query that computes the daily average.您已经拥有计算每日平均值的聚合查询。 All that is let to do is sort and limit:所要做的就是排序和限制:

select dayname(d.DAY) day_name, avg(d.VISITORS_NUMBER)  avg_vis
from dane_2 d
group by dayname(d.DAY) 
order by avg_vis desc
limit 1

Note: DAY is a reserved word in MySQL, so not a good choice for a column name (I qualified it with the table alias to avoid errors).注意: DAY是 MySQL 中的保留字,因此不是一个好的列名选择(我用表别名对其进行了限定以避免错误)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM