View RSS Feed


SQL with SUM, group, order, left join, exclude and limit

Rate this Entry
by , 05-13-2010 at 09:00 AM (1974 Views)
So I came across a scenario where I need to know the top developers of applications based on how many times their software has been downloaded.

There are 3 tables involved here.
The developers table
the orders_software table
the orders_software_downloads table

The whole goal is get this information with 1 Sql query.The basic relationships are as follows:
there are many developers in the developer table
there are many softwares to 1 order in the orders_software table
there are many downloads to 1 software to 1 order in the orders_software_downloads table.

So we select the developer name from the developer table, and the download count from the orders_software_downloads table. Left join to get all the tables together. Exclude counts that are null. Then group the results by the owner of each software. Which is a row of the software table.

This will be a great case to use SUM

we can modify the download count to sum(download_count) and as long as we have that group by, it will sum up the group.

So sql will look like this:

SELECT, SUM(orders_software_download.download_count) as sum
FROM software
LEFT JOIN orders_software on = orders_software.software_id
LEFT JOIN orders_products_download on orders_products.orders_software_id =
WHERE orders_software_download.download_count IS NOT NULLGROUP BY software.software_owner

And then from this the result will give you an array of the top developers where you can know who the developer is an how many times in total their software was downloaded

Submit "SQL with SUM, group, order, left join, exclude and limit" to Digg Submit "SQL with SUM, group, order, left join, exclude and limit" to Submit "SQL with SUM, group, order, left join, exclude and limit" to StumbleUpon Submit "SQL with SUM, group, order, left join, exclude and limit" to Google

Updated 05-13-2010 at 11:01 AM by optikalefx

Products and Technology


Leave Comment Leave Comment
View Thread

Last 3 Posts

nz gifts and nz gift
It's not free so you won't be seeing open anything. There is a free version that supports emails and google searches but the actual sms portion is $7. A very important thing to note is that this is cloud based speech recognition which means you have a big problem if 3g/4g service drops out and you need to send a text (happens a lot when driving depending on where you live).

Similar tech for pc's is available from at&t but at a much higher licensing fee. Couldn't find anything about Linux availability though.
Let me do some more research, but I'm pretty sure AT&T does have an API for this. She kept talking about this speech to text isn't an app from AT&T its a technology for developers to use.