如何使用avg函数? [英] How to use avg function?

查看:96
本文介绍了如何使用avg函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是php和mysql的新手,我正在尝试使用av​​g函数,但我不知道该怎么做.

I'm new at php and mysql stuff and i'm trying to use an avg function but i don't know how to.

我正在尝试做这样的事情:

I'm trying to do something like this:

mysql_connect(localhost,$username,$password);

@mysql_select_db($database) or die ("Did not connect to $database");

mysql_query("AVG(column1) FROM table1 ") or die(mysql_error());

mysql_close();

echo AVG(column1);

(Q1)我想查看屏幕上打印的值,但是除了一条错误消息外,我什么也没得到.如何在屏幕上打印此平均值?

(Q1)I'd like to see the value printed in the screen, but i'm getting nothing but an error message. How could I print this average on the screen ?

(Q2)如果我的表1中有一个列月份,该如何按月份打印平均值?

(Q2)If I had a column month in my table1, how could I print the averages by the months ?

对不起,英语不好,谢谢您的关注.

Sorry for any bad English, and thanks for the attention.

推荐答案

第一季度的解决方案: 从table1中选择AVG(column1)

第二季度的解决方案: SELECT AVG(column1),每月from table1 GROUP BY month

这篇关于如何使用avg函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆