aggregate-functions

How to create a MEME algorithm?

if you don't know what does meme mean you can read this article readwriteweb my question is how to create a meme algorithm, I have a website which aggregated thousands of blogs posts and I want to figure the most talked about stories. see this quotation from the article above "Meme aggregation attempts to cut down on the signal t...

Projecting aggregates together with Entity using NHibernate

I have a pretty standard Orders table and an associated OrderRows table, say: Orders [id] INTEGER [name] ... OrderRows [orderId] INTEGER [quantity] INTEGER [unitPrice] SMALLMONEY [description] VARCHAR(...) For some situations I would like to retrieve a list of Orders together with a summary of totals, most of the time I don't care fo...

Missing 'Median' Aggregate Function in Django?

The Development version of Django has aggregate functions like Avg, Count, Max, Min, StdDev, Sum, and Variance (link text). Is there a reason Median is missing from the list? Implementing one seems like it would be easy. Am I missing something? How much are the aggregate functions doing behind the scenes? ...

Aggregate Function not available as Article in Merge Rep Publication

I have Merge Replication set up and I just noticed that a Aggregate Function is not available on my Subscriber. After further investigation I discovered that is is not even available in the Publication as an option. There are other Functions listed there but not that one. Ideas? Is there something written that doesn't allow Aggregate...

Taking an average in SQL after throwing away outliers

I have a generic log table which I can attach to processes and their results. I get the average time using a process performance view: WITH Events AS ( SELECT PR.DATA_DT_ID ,P.ProcessID ,P.ProcessName ,PL.GUID ,PL.E...

SQL simplify a characteristic function? or PIVOT tables?

I have this a Table with a bunch of dates and prices: Room Name, Price, Bookdate, etc And I can transform it like so: (which essentially flips the columns) SELECT availables.name, rooms.id, MAX(IF(to_days(availables.bookdate) - to_days('2009-06-13') = 0, availables.price, '')) AS day1, MAX(IF(to_days(availables.bookdate) - to_days...

Is there a way to do aggregate functions on Google App Engine?

One of the nice things relational databases support are the aggregate functions like count, sum, avg etc. But it seems that if you are using GAE, when inserting or updating a record you must calculate and store the count, sum, avg, etc. values of the whole table. But what if you have many conditional groupings? Given a Person: class Per...

How can i write my own aggregate functions with sqlalchemy?

How can I write my own aggregate functions with SQLAlchemy? As an easy example I would like to use numpy to calculate the variance. With sqlite it would look like this: import sqlite3 as sqlite import numpy as np class self_written_SQLvar(object): def __init__(self): import numpy as np self.values = [] def step(self, value)...

Select distinct from usercolumn and minimum value of dates for each field in usercolumn

Hello I have some data like this but more than 1500000 records and more than 700 users: usercolumn , datecolumn\ a1 , 1998/2/11\ a2 , 1998/3/11\ a1 , 1998/2/15\ a4 , 1998/4/14\ a3 , 1999/1/15\ a2 , 1998/11/12\ a2 , ...

Getting MIN Price in Subquery in SQL Server (using DISTINCT)?

Hi there, I am trying to get a Minimun price from a car in a table i have.. I am using DISTINCT SELECT DISTINCT datepart(year,[Registration]) AS YearRegistered, MIN(SalePrice), Model, Make FROM [VehicleSales] But its not working, for example without distinct returns many car makes and models so i use distinct so i get unique ca...

Aggregate function with Date on Postgres

I'm kind of rusty on my SQL, maybe you can help me out on this query. I have these two tables for a tickets system (I'm omitting some fields): table tickets id - bigint subject - text user_id - bigint closed - boolean first_message - bigint (foreign key, for next table's id) last_message - bigint (same as before) table ticket_me...

Do aggregate MySQL functions always return a single row?

I'm sorry if this is really basic, but: I feel at some point I didn't have this issue, and now I am, so either I was doing something totally different before or my syntax has skipped a step. I have, for example, a query that I need to return all rows with certain data along with another column that has the total of one of those columns...

DB2 SQL - median with GROUP BY

Hi everybody, First of all, I am running on DB2 for i5/OS V5R4. I have ROW_NUMBER(), RANK() and common table expressions. I do not have TOP n PERCENT or LIMIT OFFSET. The actual data set I'm working with is hard to explain, so let's just say I have a weather history table where the columns are (city, temperature, timestamp). I want ...

Performance of Aggregate Functions on Large Infrequently Changing Datasets

I need to extract some management information (MI) from data which is updated in overnight batches. I will be using aggregate functions to generate the MI from tables with hundreds of thousands and potentially millions of rows. The information will be displayed on a web page. The critical factor here is the efficiency of SQL Server's han...

Function to Calculate Median in Sql Server

According to MSDN, Median is not available as an aggregate function in Transact-Sql. However, I would like to find out whether it is possible to create this functionality (using the Create Aggregate function, user defined function, or some other method). What would be the best way (if possible) to do this - allow for the calculation of...

Count function in HQL causing null results?

I have the following HQL query that is attempting to return 2 object instances as well as an aggregate count based upon a 3rd object instance. SELECT client, clientCampaign, count( formData ) FROM FormData as formData JOIN formData.deliveryResults as deliveryResults JOIN formData.leadForm as leadForm JOIN leadForm.campaignForms a...

SQL aggregate functions using MIN and AVG...

How can I omit Zeros in my data? For example using the MIN function? I would like the Minimum value except a 0... How can I get the next largest? MIN(availables.price) Also is there a generally way to skip over 0s in the same way if I'm using the AVG function? The problem is the table I've inherited doesn't use NULL values but has...

How do I get a sequence's MINVALUE in Oracle 10g PL/SQL?

I wrote a PL/SQL script to set a sequence's value to the maximum value of a table's primary key: DECLARE max_idn NUMERIC(18, 0); seq_nextval NUMERIC(18, 0); increment_amount NUMERIC(18, 0); BEGIN SELECT MAX(mbr_idn) INTO max_idn FROM mbr; SELECT mbr_seq.nextval INTO seq_nextval FROM DUAL; increment_amount := max_id...

MYSQL : First and last record of a grouped record (aggregate functions)

I am trying to do fectch the first and the last record of a 'grouped' record. More precisely, I am doing a query like this SELECT MIN(low_price), MAX(high_price), open, close FROM symbols WHERE date BETWEEN(.. ..) GROUP BY YEARWEEK(date) but I'd like to get the first and the last record of the group. It could by done by doing tons of ...

How to sort by annotated Count() in a related model in Django

Hi, I'm building a food logging database in Django and I've got a query related problem. I've set up my models to include (among other things) a Food model connected to the User model through an M2M-field "consumer" via the Consumption model. The Food model describes food dishes and the Consumption model describes a user's consumption o...