aggregate

SQL: aggregate function and group by

Consider the Oracle "emp" table. I'd like to get the employees with the top salary with department = 20 and job = clerk. Also assume that there is no "empno" column, and that the primary key involves a number of columns. You can do this with: select * from scott.emp where deptno = 20 and job = 'CLERK' and sal = ( selec...

Why are SQL aggregate functions so much slower than Python and Java (or Poor Man's OLAP)

I need a real DBA's opinion. Postgres 8.3 takes 200 ms to execute this query on my Macbook Pro while Java and Python perform the same calculation in under 20 ms (350,000 rows): SELECT count(id), avg(a), avg(b), avg(c), avg(d) FROM tuples; Is this normal behaviour when using a SQL database? The schema (the table holds responses to a s...

UML aggregation when interfaces are used

How do I represent an aggregation relation between two classes in UML, such that each class has a link to the other class's interface, not the implementing class? E.g. I have a class Foo that implements iFoo, and Bar that implements iBar. Foo should have a member variable of type iBar, and Bar should have a member variable of type iFoo....

NDepend CQL Count Query

I want to query a table of public methods of a specific class and a count of each methods usage in NDepend CQL. Currently query looks like this: SELECT METHODS FROM TYPES "AE.DataAccess.DBHelper" WHERE IsPublic Is it possible to aggregate queries in CQL? ...

How to use GROUP BY to concatenate strings in MySQL?

Basically the question is how to get from this: id string 1 A 1 B 2 C to this: id string 1 A B 2 C ...

How to join the newest rows from a table?

I frequently run into problems of this form and haven't found a good solution yet: Assume we have two database tables representing an e-commerce system. userData (userId, name, ...) orderData (orderId, userId, orderType, createDate, ...) For all users in the system, select their user information, their most recent order information w...

Summing Split ranges in a SQL query

I have a table which contains my server status create table ServerStatus ( ServerId int, StartTime datetime, Seconds int, [State] char(8) ) I would like a query that given a start and end date will summarize the time the server spends in each state during that time. I would also like the query to return the amount o...

how to use google feed api to detect feeds updates

Because I run a blog aggregator website which checks a large list of RSS feeds for new posts every hour so I will be happy if its possible to use google feed api or Google AJAX Feed API instead of making the cron jobs to read the whole feed to know if its updated or not. like this link text ...

Aggregate adjacent only records with T-SQL

Hi, I have (simplified for the example) a table with the following data Row Start Finish ID Amount --- --------- ---------- -- ------ 1 2008-10-01 2008-10-02 01 10 2 2008-10-02 2008-10-03 02 20 3 2008-10-03 2008-10-04 01 38 4 2008-10-04 2008-10-05 01 23 5 2008-10-05 2008-10-06...

Most succinct LINQ To SQL for taking COUNT(*) of either side of many-to-many?

Please help me with a sanity check. Assuming a many-to-many relationship: What's the most succinct way (using LINQ to SQL) to get a result set showing, for each tag (or post), the aggregate number of posts (or tags) assigned to it? Thanks! ...

Flatten a recordset in SQL Server?

Say you get a recordset like the following: | ID | Foo | Bar | Red | |-----|------|------|------| | 1 | 100 | NULL | NULL | | 1 | NULL | 200 | NULL | | 1 | NULL | NULL | 300 | | 2 | 400 | NULL | NULL | | ... | ... | ... | ... | -- etc. And you want: | ID | Foo | Bar | Red | |-----|-----|-----|-----| | 1 | 100 | ...

Howto check for existing aggregate functions in Postgres?

In Postgresql you can create additional Aggregate Functions with CREATE AGGREGATE name(...); But this gives an error if the aggregate already exists inside the database, so how can I check if a Aggregate already exists in the Postgres Database? ...

SQL group by day, show orders for each day

I have an SQL 2005 table, let's call it Orders, in the format: OrderID, OrderDate, OrderAmount 1, 25/11/2008, 10 2, 25/11/2008, 2 3, 30/1002008, 5 Then I need to produce a report table showing the ordered amount on each day in the last 7 days: Day, OrderCount, OrderAmount 25/11/2008, 2, 12 26/11/200...

MySQL finding subtotals

EDIT: I'm told that making you guys read means I get less attention. My apologies. Here's a simpler version: Bill got $100 dollars worth of items from a store. He wants to return enough of the items to get exactly $30 dollars back. The store has a Point of Return system that will help him do this. Here is the data after he scans his...

Sum IIF Expression

Im trying to sum an expression in visual studio and just keep getting an #error but not sure why as this si the first time i have tried to sum an expression, only ever done it on a single field before. Any Suggestions!!! =IIf(Fields!STATUS.value = "Completed" AND Fields!DONOTINVOICE.value = True, Fields!ORDERCOST.Value, "") ...

Repository Pattern: how to Lazy Load? or, Should I split this Aggregate?

I have a domain model that has the concept of an Editor and a Project. An Editor owns a number of Projects, and a Project has not only an Editor owner, but also a number of Editor members. Therefore, an Editor also has a number of "joined" Projects. I am taking a DDD approach to modelling this and using the Repository pattern for pers...

How to handle large amounts of data for a web statistics module

Hi, I'm developing a statistics module for my website that will help me measure conversion rates, and other interesting data. The mechanism I use is - to store a database entry in a statistics table - each time a user enters a specific zone in my DB (I avoid duplicate records with the help of cookies). For example, I have the followin...

Does the Rails ORM limit the ability to perform aggregations?

I am concerned whether Rails can handle the types of complex aggregations that are needed for a financial application and particularly whether the ORM can handle these effectively. In a financial application that I am thinking of using this for, there is a need to do lots of reporting of detailed financial data, aggregated in various way...

SQL aggregate functions

hello, I have a similar question to this one http://stackoverflow.com/questions/501347/sql-products-productsales I want to do that same query but instead of just checking quantity i want to check "total" (ie. quantity * price). "price" is a field in the sales table. here is the original query suggested on that link: SELECT p.[name] ...

How do you handle associations between aggregates in DDD?

I'm still wrapping my head around DDD, and one of the stumbling blocks I've encountered is in how to handle associations between separate aggregates. Say I've got one aggregate encapsulating Customers and another encapsulating Shipments. For business reasons Shipments are their own aggregates, and yet they need to be explicitly tied to ...