avg

AVG time spent on multiple rows SQL-server?

I have a table tblSequence with 3 cols in MS SQL: ID, IP, [Timestamp] Content could look like this: ID IP [Timestamp] -------------------------------------------------- 4347 62.107.95.103 2010-05-24 09:27:50.470 4346 62.107.95.103 2010-05-24 09:27:45.547 4345 62.107.95.103 2010-05-24 09:...

How to use avg function?

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 AV...

Strange Access Denied warning when running the simplest C++ program.

I am just starting to learn C++ (coming from a Java background) and I have come across something that I can't explain. I am working through the C++ Primer book and doing the exercises. Every time I get to a new exercise I create a new .cpp file and set it up with the main method (and any includes I think I will need) e.g.: #include <l...

Average of grouped rows in Sql Server

Hi there. I have an Sql Server Table.. it's something like this: Id ...... Column1 ...... Column2 ```````````````````````````````` 1 ........ 1 ............. 34 2 ........ 1 ............. 44 3 ........ 2 ............. 45 4 ........ 2 ............. 36 5 ........ 2 ............. 23 6 ........ 3 ............. 68 7 ..........

AVG() fuction always returning "Array"

This is what I got, UPDATED $avg_query = "SELECT AVG(rating) AS avg_rating FROM kicks WHERE userid='$userid'"; $avg_result = mysqli_query($cxn, $avg_query) or die("Couldn't execute query."); $row = mysqli_fetch_assoc($avg_result); $average = $row['avg_rating']; E...

T-SQL average function - count 52 rows of data

I need help writing select statement that will do an average of the most recent 52 rows of data. If there is less then 52 rows it will only do the avg of how many rows there are. I know the avg function in SQL will skip the null...but i got this far. SELECT AVG(E.Interest) from InterestRates E Where Interest in (select COUNT(Interest)...

Problem using nested avg(..) aggregate function in hibernate hql

I am using HQL to get data through DAO class but it throws as error stated below : ERROR org.hibernate.hql.PARSER - <AST>:0:0: unexpected AST node: query Below is my Hql Query : select new com.shaikh.dto.UserResult ( user.userSurName, avg((select avg(v1.age) from com.shaikh.dto.UserResult v1 where v1.joinDate between to_date(:dayF...

Average time from DateTime dataset in SQL Server 2005

I am trying to get the avg time a driver completed a delivery stops at each unique customer. I am using the following columns: Name (varchar(50)) Reference1 (varchar(50)) CompletedTime (Datetime). I am getting an avg but it includes the date & time NOT just date. Which is making the time avg incorrect. thanks for the help! Current...

Optimize query with AVG() and group by on a big table?

I am wondering if there is a way to optimize this query: SELECT Avg(selloff1), YEAR(dt), weekno FROM bbproduct GROUP BY YEAR(dt), weekno Table schema is: CREATE TABLE `bbproduct` ( `id` bigint(20) NOT NULL, `CUSTNO` decimal(6,0) unsigned zerofill NOT NULL default '000000', `DEPTNO` decimal(1,0) uns...

MySQL - working out the AVG for a subset of MAX values

Hi all, I have a table with columns 'Date, Name, Score'. I wish to get the MAX(Score) for rows which share a common value (for e.g. the same date or even name), before averaging them to give me a figure, for example: ---- Date -----| -- Name -- | Score 2010-10-10 | John Smith | 86 2010-06-05 | Tedi Jones | 71 2010-10-10 | John Smith |...

mysql avg() not working as expected

Hello, I'm having some trouble with MySql right now. I have an query that works just fine, I'm using it for a while, but today I got stuck with this. The query is: select avg(valor), tipo_id, users_id, datetime from entries where users_id = '1' and tipo_id = 1 and date_format(datetime,"%Y-%m-%d") between "'2010-09-20" and "2010-10-20"...

SQL database queries basic question AVG Difference

I have a really basic question on SQL. Relational Schema: Student (Sid, Sname ) Class (Sid, ClassName, mark) ClassName = { MATH, ENGLISH, PHY, .......} I want to list out all the student who have taken MATH, and their MATH class average minus the student's math mark Select DINSTINCT S.Sname, (E.Mark - AVG (E.Mark)) From Student ...