order-by

Mysql query, three tables left join with group by.

Hi, I have query which provide wrong result, am I doing any thig wrong in this query SELECT b.nBoutiqueID , b.sBoutiqueName , b.Status , SUM(bs.nViewCount) nViewCount , SUM(ps.nViewCount) nProductViewCount, ...

IEnumerable OrderBy

I'm using IEnumerable orderby to sort my items in ascending format but it does not work my query is like this: IEnumerable<Step> steps = allsteps.Where(step => step.X <= Y); steps = steps.OrderBy(step => step.X); its not deffer to use OrderBy or OrderByDescending why? I'm want to use Sum() method to sum some items and item orders i...

Ruby on Rails get records by highest price

Hey, I have a model Rails model called Orders that has a type_id, location, and price. Each type can have multiple orders at the same location with different prices. Check below for a idea of the table structure. id | type_id | location_id | price ----------------------------------- 1 | 1 | 1 | 12 2 | 1 | 1 ...

Another LINQ OrderBy query

I have a table (as in a list of numbers) that gets recreated through a series of linq queries. I'm trying to sort the columns in descending order based upon the values within the first row. My Database looks like this: Data { ColumnLabel, RowLabel, Value } {"Cat", "All", 9} {"Dog","All", 17} {"Fish", "All", 4} {"Cat", "Girl...

GROUP BY and ORDER BY in same MySQL query?

I want to select a bunch of data from a table using a GROUP BY clause. This works great, but I need to order the data by the date it was created, with an ORDER BY clause. My question is, can I use both these clauses within the same query, or should I be using one in a sub-query, or something else? The original query (no modification) is...

Help With Generic LINQ OrderBy Lambda Expression

Hi Guys, Trying to get an OrderBy on an IQueryable to work, not having much luck. Here's my method: public ICollection<T> FindAll<T>(Expression<Func<T,bool>> predicate, Expression<Func<T,int>> orderingKey) where T : Post { return repository .Find() .Where(predicate) .OfType<T>() ...

Linq - 'Saving' OrderBy operation (c#)

Assume I have generic list L of some type in c#. Then, using linq, call OrderBy() on it, passing in a lambda expression. If I then re-assign the L, the previous order operation will obviously be lost. Is there any way I can 'save' the lambda expression I used on the list before i reassigned it, and re-apply it? ...

LINQ Order By to select lowest Index

I am relatively new to LINQ and don't know how to do an Order By. I have an IEnumerable list of myObject and want to do something like select first myObject from myObjectList order by myObject.id asc How can I accomplish this? Thanks ...

If using LINQ For Queries, Do We Need to Unit-Test Sorting?

Hi Guys, I have the following two methods on an interface for my service layer: ICollection<T> FindAll<T>(Expression<Func<T, bool>> predicate) where T : Post; ICollection<T> FindAll<T,TKey>(Expression<Func<T, bool>> predicate, OrderingOptions<T,TKey> orderingOptions) where T : Post; They are extremely similar. The first one (basica...

Using GQL sort by the count of a ListProperty

If I have an db.Model object such as: class Foo(db.Model): title = db.StringProperty() bars = db.ListProperty(db.Key) and I wanted to query the datastore for all of the Foo entities and sort that set by the Foo objects that have the most bars, how would I write the GQL? I was hoping for something as simple as: fooQuery = db....

UNION ALL, TEXT field and ORDER BY error

Hi, Im having two tables with attributes like date(datetime),headline(varchar),text(text) Now i want to UNION ALL these two tables and sort by the datetime. When doing this i'm getting the error: Only text pointers are allowed in work tables, never text, ntext, or image columns. The query processor produced a query plan that requir...

SQL - Order after filtering

How can I order the data and then filter it in TSQL (SQL Server)? I've tried something like this: SELECT [Job].*, ROW_NUMBER() OVER (ORDER BY [Job].[Date]) AS RowNum FROM [Job] ORDER BY Rank WHERE RowNum >= @Start AND RowNum < @End Doesn't work. I also tried to use a subquery, which throws: The ORDER BY clause is invalid ...

Conditional SQL ORDER BY ASC/DESC for alpha columns

Writing a stored procedure in MS SQL Server 2008 R2, I want to avoid using DSQL... I would like the sort method (ASC or DESC) to be conditional. Now, with a numeric column I would simply use a case statement and negate the value to emulate ASC or DESC... That is: ... ORDER BY CASE @OrderAscOrDesc WHEN 0 THEN [NumericColumn] ELSE -[Num...

Linq orderby two-column sort with custom comparer

List<MyObject> objects = (from a in alist join b in blist on a.ID equals b.ID where a.Number != 4 orderby b.Rank, a.CustomField select a).ToList(); This is my query and I want to use a custom Comparer for the CustomField property. Is there a way to do that in a two-field orderby? I am able to do this: List<MyObject> o...

What is the MS SQL Server capability similar to the MySQL FIELD() function?

MySQL provides a string function named FIELD() which accepts a variable number of arguments. The return value is the location of the first argument in the list of the remaining ones. In other words: FIELD('d', 'a', 'b', 'c', 'd', 'e', 'f') would return 4 since 'd' is the fourth argument following the first. This function provides t...

MySQL Ordering Lists Question

Hi All, I have the following code: SELECT q21coding, COUNT(q21coding) AS Count FROM `tresults_acme` WHERE q21 IS NOT NULL AND q21 <> '' GROUP BY q21coding ORDER BY Count DESC It brings back the following: q21coding Count Difficulty in navigating/finding content 53 Positive comm...

NHibernate Criteria API - order by max of two properties

Hi, I have a PrivateMessage class and I want to get list of PMs for user sorted chronologically either by CreationDate or LastAnswerDate (depending on which is more recent) using Criteria API. How to sort by max of these two properies in Criteria API? My code looks similar to following: var dc = DetachedCriteria.For<PrivateMessage>(); ...

MySQL Ordering a query - further question

Hi all, Further to a recently answered question, I have the following code: SELECT q21coding, COUNT(q21coding) AS Count FROM tresults_acme WHERE q21 IS NOT NULL AND q21 <> '' GROUP BY q21coding ORDER BY IF(q21coding = 'Other', 1, 0) ASC, Count DESC It brings back the following: q21coding ...

Why does Oracle return specific sequence if 'orderby' values are identical?

I'm bewildered by a query in Oracle which is returning in a seemingly random order. SELECT Date, Amount FROM MyTable WHERE Date = '26-OCT-2010' ORDER BY Date This returns the following data: | Date | Amount -------------------------- 1 | 26-OCT-10 | 85 2 | 26-OCT-10 | 9 3 | 26-OCT-10 | 100 I cannot fathom...

Can you sort Typed DataSet DataTables with Linq OrderBy?

I have a Typed DataSet DataTable which inherits TypedTableBase<T>, which in turn implements IEnumerable<T>. I can't seem to get this to work. myDataTable.OrderBy(x => x.ID).ThenBy(y => y.ID2); Instead I have to assign this statement to an IEnumerable(or List), then refill my DataTable manually with the newly ordered IEnumerable before...