Most efficient way to retrieve “top x” records using Rails
We've gotten a report request in, and I'm trying to find out the easiest and most efficient way to pull the numbers.
I have a Deal model with two attributes: _quantity_purchased_ and price. I've been asked to retrieve a list of the top 100 best selling deals in the database. To see how well a deal has done, we multiply the quantity_purchased by the price.
Now, I'm sure I could write something convoluted to get my results, but this seems like such a simple operation, that there has got to be an easier way of doing it. Is there something I could do in MySQL, or using Ruby/Rails? Or am I stuck finding some kind of unpleasant loop?
FYI, we are running Rails 2.3.
The .Net framework now has (at least) four different methods of reading an Xml string. I've used each of XmlDocument, XmlReader, XPath and XElement, but which is the most efficient to use when coding
There are many ways of converting a String to an Integer object. Which is the most efficient among the below: Integer.valueOf() Integer.parseInt() org.apache.commons.beanutils.converters.IntegerConver
Say I have a string of 16 numeric characters (i.e. 0123456789012345) what is the most efficient way to delimit it into sets like : 0123-4567-8901-2345, in PHP? Note: I am rewriting an existing system
I have a string in this format: ABC_123_ I want to end up with and integer variable that is just the number portion of the string. What is the most efficient way to accomplish that in C#?
In C++, I use a singleton class and refer to the only instance in another class. I'm wondering what is the most efficient way to access this instance since it is a large data structure. I considered t
I am seeking for most efficient way (in terms of speed) to retrieve some file out of the middle of a ZIP file. e.g. I have ZIP file, which includes 700 folders (tagged 1 to 700). Each folder equals p
In ruby, what is the most efficient way to calculate the bit difference between two unsigned integers (e.g. the hamming distance)? Eg, I have integer a = 2323409845 and b = 1782647144. Their binary r
I have started using M-x compile to compile programs in say, C. What is the most efficient way to run the executable e.g. a.out. At the moment I'm using M-! ./a.out. Basically, what is the best code-c
I'm trying to figure out what is the most efficient way to parse data from a file using Lua. For example lets say I have a file (example.txt) with something like this in it: 0, Data 74, Instance 42949
I have 3 lists of type ::[Integer] , which are sorted from smallest to largest ,all of arbitrary and different lengths, what would be the most efficient way to find all common integers, if any exist,
I'm looking to turn 165 seconds into 2:40 not 0:2:45 The function needs to be able to adapt to how large the seconds value is. I know there's infinite ways to do this, but I'm looking for a clean way
I have a list of 300 numbers, they are not ordered. I would like to find the most efficient way to determine if a number is in that list. The simple answer is in_array(). This of course has a Big O of
As the title suggests, I have a file containing vocabularies (each on a single line) sorted in A-Z and I would like to retrieve all vocabularies with a given prefix. The problem is that the file conta
What is the most efficient way of getting current time/date/day/year in C language? As I have to execute this many times, I need a real efficient way. I am on freeBSD. thanks in advance.
In a single-select-statement, I have the need to RTRIM a string in a SQL Server 2005 environment. What is, in your opinion, the most efficient technique to achieve this? Examples: 'ALPHA ' ==> 'ALP
I'm looking for the best solution to solve this problem : I have a client and a server. The client sending request to the server using the call.invoke method. The call for now is synchronous and waiti
I am going to update a table using the sum of specific value from 3 different tables. For this purpose I wrote this query. But it takes too much time, what is the most efficient query for this purpose
I have four different types of objects within my environment(box2d), each type of object having multiple instances of itself, and would like to find the most efficient way to deal with adding and mani
I have to write a java code to add minutes(delayminutes) to a timestamp(tmpTimeStamp). This is what I have. I was wondering if this is an efficient way to do this or if there is a better way. long t=t
How do you delete multiple records using checkboxes in Rails 3?
I was wondering what the most computationally efficient Python way of cracking this problem would be. Say you have two strings (or lists from splitting those strings--doesn't matter), this is the rig
What is the most efficient(fast and safe) way of reading a log file in java? The log file continuously(almost every second) gets updated.
x86 does not have an SSE instruction to convert from unsigned int32 to floating point. What would be the most efficient instruction sequence for achieving this? EDIT: To clarify, i want to do the vect
what should answer to this google-interview? What is the most efficient way to choose a random value in a stream? Given that each of them has a chance of occurring equally. Thanks.
What is the most efficient way to get the content-type of a given URL using Ruby?
I have always been curious about this as the simple way is definitely not efficient. How would you efficiently go about outputting a value every x seconds? Here is an example of what I mean: import ti
What is the most efficient (fastest) way to get a lower bound of zero? Math.max(0, x) will work, returning 0 for any negative value of x. However, my experience with Math.* is that there often is a fa
What is the most efficient way, in terms of cost and scalability, to pull stats on large volumes of data? Let's take a concrete example, there are 1000 companies, each with 10000+ customers. These com
I'm currently looking to store approximately 3.5 million photo's from approximately 100/200k users. I'm only using a mysql database on aws. My question is in regards to the most efficient way to store
What is the fastest way to delete records from a SQL Server database for a large year-end purge, when the query has to join to another table? I understand cursors are slow. Do I do DELETE FROM table1
What is the most efficient way from the time consumed to read a text file into a list of binary strings in erlang ? The obvious solution -module(test). -export([run/1]). open_file(FileName, Mode) ->
I have a datagridview in which a user is allowed to retriev either n records (using textbox) or All records by clicking on a buttun Now want to retrieve Top N records Or All Records with a single Quer
For integration testing I need to wipe all data information in a database. I'm using Entity Framework 4 What's the most efficient way? Would be nice if I don't need to specify table or class names eve
What's the most efficient way to iterate through an entire table using Datamapper? If I do this, does Datamapper try to pull the entire result set into memory before performing the iteration? Assume,
Is there a more efficient way to write the following appendChild / nesting code? var sasDom, sasDomHider; var d = document; var docBody = d.getElementsByTagName(body); var newNode = d.createEleme
I am trying to work out the most efficient query to get points within a radius of a given point. The results do not have to be very accurate so I would favor speed over accuracy. We have tried using a
Which way to assign values to a map is most efficient? Or are they all optimized to the same code (on most modern compilers)? // 1) Assignment using array index notation Foo[Bar] = 12345; // 2) Ass
I want to get top five most repeating records from a table in link to Entity Framework 4.0. How it can be possible in a single query which returns a list of collection of five records?
I have 100,000 records. I need to elevate the top 10,000 records using elevate.xml. How can I do this?
I'm using Hibernate to retrieve the number of rows for a specific query. Let's say I have a table called 'Person' with various columns. One of those columns is 'name'. If I wanted to get the number of
I'm new with Ruby on Rails and want to get several records into the SQLite3 database so that I can manipulate the data. I am following a lesson, and wonder what is the fastest, most effective way to g
What is the most efficient way to search a list of objects and also increment one of its variables? Also addData() function call 10000 time and in this list have max 30 diff-diff key with increment va
What datatype is the most efficient to store a number such as 11.111. The numbers will have up 2 digits before the point and up to three after. Currently the column is a 'bigint', I am guessing that t
I want to get a list but the last and the first elements. What is the most efficient way? middle = init . tail or: middle = tail . init And in the case of drop the n-first elements and the n-last el
I'm quite new to php so I'm wondering what the most efficient way is to do this. For exmaple I have 3 different colors for 3 cars as variables. So car 1 gets color 1, car 2 color 2 and car 3 color 3.
I am looking for the most efficient way of converting image file to Base64 String in Android. The image has to be sent in a single Base64 String at once to backend. First I use imageToByteArray and th
I am working with big and complex dictionary data (XML) which needs to be parsed by XSL and output XML. what would be considered as a best way to test if XSL is processing all nodes from XML (input)
What is the most memory efficient way to search within a string in ANSI C? (put the code up) An example where this is needed is in embedded devices that are very short on available memory but nowadays
I am trying to collect performance data from vcenter for hosts. I've created this powershell script. It works but it takes a extremely long time to complete. Is there a better more efficient way to re