sql-order-by

what is this order by 1?

三世轮回 提交于 2019-12-21 07:12:31
问题 I had a question in MySQL, did it correctly. But the book code differs a little. Book: use tennis; select playerno, datediff(coalesce(end_date, current_date), begin_date) as Difference, position from committee_members where datediff(coalesce(end_date, current_date), begin_date) > 500 order by 1; What is this order by 1 ? My code also works and is almost the same except: select playerno, datediff(coalesce(end_date, current_date) AS Data, order by Data; 回答1: order by 1 means "order by the first

ORMLITE ORDER_BY with multiple columns

本小妞迷上赌 提交于 2019-12-21 07:05:00
问题 I am using ormlite in my recent android project. I want to order by on a query on multiple columns in a table (say two columns). How can I achieve that?? Here is the code for a single order by... QueryBuilder<Visit, Integer> qb = getHelper().getVisitDao().queryBuilder(); qb.where().eq("FOREIGN_ID", id); qb.orderBy("VISIT_DATE", false); 回答1: I want to order by on a query on multiple columns in a table(say two columns). How can i achieve that?? All you need to do is to call orderBy(...)

Sql Order by on multiple column

放肆的年华 提交于 2019-12-21 03:41:04
问题 I've the below result VendorName | IncidentID | IncidentStatus | IncidentDate ------------------------------------------------------- XYZ | 100 | Open | 02-JUN-2011 XYZ | 101 | Open | 03-JUN-2011 ABC | 102 | Open | 01-JUN-2011 XYZ | 103 | Open | 01-APR-2011 ABC | 105 | Open | 05-JUN-2011 I want to order VendorName which has latest incident. Vendor ABC has the latest incident hence it should come first with all other incident for same vendor and then next Vendor with all respective incident in

Basic Rails 3 question: How to sort products?

我的未来我决定 提交于 2019-12-21 02:57:30
问题 I have the following models: Product: name, shop_id (foreign key), brand_id (foreign key), price Shop: name Brand: name The associations are: Product: belongs_to :shop belongs_to :brand Shop: has_many :products has_many :brands, :through => :products Brand: has_many :products has_many :shops, :through => :products In ProductsController#list I would like to get a list of all products sorted by shop name and then by brand name. I tried to do: @products = Product.order("products.shop.name ASC,

Laravel MySQL orderBy count

旧城冷巷雨未停 提交于 2019-12-20 23:26:48
问题 I'm using Laravel and MySQL, and I have a table post that represents post where users can comment on it, now I wanna order posts by the number of comments of each post in ascending/descending order, how do I do this in Laravel? I don't want to add a field in post table to keep track of the number of comments of each post, because updating that field manually each time a comment or a comment's comment is added/deleted drives me crazy... This is how I create my posts table and comments table:

How to dynamically order many-to-many relationship with JPA or HQL?

被刻印的时光 ゝ 提交于 2019-12-20 14:15:36
问题 I have a mapping like this: @ManyToMany(cascade = CascadeType.PERSIST) @JoinTable( name="product_product_catalog", joinColumns={@JoinColumn(name="product_catalog", referencedColumnName="product_catalog")}, inverseJoinColumns={@JoinColumn(name="product", referencedColumnName="product")}) public List<Product> products = new ArrayList<Product>(); I can fetch the products for the catalog nicely, but I can't (dynamically) order the products. How could I order them? I probably have to write a many

OrderBy and Top in LINQ with good performance

梦想的初衷 提交于 2019-12-20 12:11:13
问题 What is a good way to get the top 10 records from a very large collection and use a custom OrderBy? If I use the LINQ to Objects OrderBy method it is slow and takes a lot of memory because it creates an entire new collection with the new order. I would like a new method with the signature below that does not re-order the entire collection and is very fast: public static IEnumerable<TSource> OrderByTop<TSource, TKey>( IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey

Datatable select method ORDER BY clause

限于喜欢 提交于 2019-12-20 11:11:01
问题 HI, I 'm trying to sort the rows in my datatable using select method. I know that i can say datatable.select("col1='test'") which in effect is a where clause and will return n rows that satisfy the condition. I was wondering can i do the following datatable.select("ORDER BY col1") ---col1 is the name of hte column I tried datatable.defaultview.sort() but didnt work Any ideas on how to get around this issue. thanks 回答1: Have you tried using the DataTable.Select(filterExpression, sortExpression

How to do case-insensitive order in Rails with postgresql

梦想与她 提交于 2019-12-20 10:26:44
问题 I am in the process of switching my development environment from sqlite3 to postgresql 8.4 and have one last hurdle. In my original I had the following line in a helper method; result = Users.find(:all, :order => "name collate NOCASE") which provided a very nice case-insensitive search. I can't replicate this for postgresql. Should be easy - any ideas? Thanks. 回答1: result = Users.find(:all, :order => "LOWER(name)") To take a little bit from both Brad and Frank. 回答2: LanecH's answer adapted

Is MySQL LIMIT applied before or after ORDER BY?

Deadly 提交于 2019-12-20 09:48:13
问题 Which one comes first when MySQL processes the query? An example: SELECT pageRegions FROM pageRegions WHERE(pageID=?) AND(published=true) AND (publishedOn<=?) ORDER BY publishedON DESC LIMIT 1'; Will that return the last published pageRegion even if the record does not match the revision datetime IF LIMIT is applied after ORDER BY? 回答1: Yes, it's after the ORDER BY. For your query, you'd get the record with the highest publishedOn, since you're ordering DESC , making the largest value first