sql-order-by

MySQL: GROUP_CONCAT with an ORDER BY COUNT?

喜你入骨 提交于 2019-12-20 04:38:31
问题 Is this possible ? Let's say I have a list of addresses, with a lot of duplicate entries. I need to filter out all the duplicates, because some addresses have slightly different names but the same postalcode and telephone number. First I do a GROUP BY on postalcode and telephone. SELECT name, address, postalcode, place, phone FROM addresses GROUP BY postalcode, phone But then I get random names. I would like to get the best name, that is, the name with the most entries per postalcode/phone.

Ordering sub-items within ordered items in a Linq to Entities Query

只愿长相守 提交于 2019-12-20 03:56:13
问题 I have a few tables, Listings, ListingImages and a few others related to Listings. ListingImages is related to Listings so that you can have many ListingImages per Listing. When I query this table I do; IQueryable<Listing> ListingToSendToView = (from x in DBEntities.ListingSet.Include("ListingImages") .Include("OtherTables") where x.Listing.ID == (int)LID orderby x.ID descending select x).First(); Now this is fine. However, I now want to sort the ListingImages independently within each

SQL Case Order By specific order

谁说胖子不能爱 提交于 2019-12-20 02:45:20
问题 Ok, I asked something similar before, but I've researched it and haven't found this specifically. I have a table that I need sorted on fields OptionName(NVarChar) and IsActive(BIT). I need the results to be in the following order for a DDL: Option A Option B Option C Options that are Active, by OptionName ASC Option D Options that are Inactive, by OptionName ASC So far I have ORDER BY CASE WHEN PortalName = 'Company, Inc' THEN 0 ELSE 1 END, CASE WHEN PortalName = 'Setup' THEN 1 ELSE 2 END,

ORDER BY datetime makes the query very slow

廉价感情. 提交于 2019-12-20 01:45:43
问题 I am trying to pull data from multiple tables and when I user ORDER BY a datetime field it return the results after at least 10 seconds but if I do the same query without ORDER BY then it return the results for under 2 seconds. This is my current query SELECT ph.call_subject AS callSubject, ac.account_name AS accountName, DATE_FORMAT(ph.trigger_on, "%c/%e/%Y %h:%i %p") AS triggerOn, ind.name AS industry, cc.call_code_name AS callCode FROM phone_calls AS ph INNER JOIN accounts AS ac ON ph

ORDER BY datetime makes the query very slow

▼魔方 西西 提交于 2019-12-20 01:45:28
问题 I am trying to pull data from multiple tables and when I user ORDER BY a datetime field it return the results after at least 10 seconds but if I do the same query without ORDER BY then it return the results for under 2 seconds. This is my current query SELECT ph.call_subject AS callSubject, ac.account_name AS accountName, DATE_FORMAT(ph.trigger_on, "%c/%e/%Y %h:%i %p") AS triggerOn, ind.name AS industry, cc.call_code_name AS callCode FROM phone_calls AS ph INNER JOIN accounts AS ac ON ph

toPagedList() order differs from the LINQ order by clause

孤街醉人 提交于 2019-12-19 22:49:10
问题 I have a small application that displays a list of shortURLs to a user. I'm using ASP.NET MVC3, Entity Framework, and an Oracle backend. I'm also using the PagedList library by Troy Goode (https://github.com/TroyGoode/PagedList) I want the user to see the very last entry first, similar to how blog comments are ordered. To do this I added an "orderby descending" clause to the LINQ statement: var links = from l in db.LINKS orderby l.ID descending select l; In debug the "links" object is ordered

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

天大地大妈咪最大 提交于 2019-12-19 17:32:37
问题 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 why the database returns the data in this specific order, or why, since the original table would return the data this way. Casting Date to TIMESTAMP confirms that all Date values are the

How to make Sqlite use an index for ordering on multiple columns in the case of multiple selection from the same table?

邮差的信 提交于 2019-12-19 12:06:08
问题 I have a table with a few hundred thousand lines. (It’s a precomputed table expressing the relation between lemmas of words and other big tables.) I need to do multiple selections to find a combination of different entries, i.e. I have to use “AS” to do select … from ltc as l0, ltc as l1, ltc as l2 … order by ... The speed of the query depends on the sorting: Without sorting, it’s a few milliseconds, with sorting, it can take a few minutes. This is due, as far as I can tell, to the temporary

How to make Sqlite use an index for ordering on multiple columns in the case of multiple selection from the same table?

江枫思渺然 提交于 2019-12-19 12:06:01
问题 I have a table with a few hundred thousand lines. (It’s a precomputed table expressing the relation between lemmas of words and other big tables.) I need to do multiple selections to find a combination of different entries, i.e. I have to use “AS” to do select … from ltc as l0, ltc as l1, ltc as l2 … order by ... The speed of the query depends on the sorting: Without sorting, it’s a few milliseconds, with sorting, it can take a few minutes. This is due, as far as I can tell, to the temporary

Reverse the “natural order” of a MySQL table without ORDER BY?

偶尔善良 提交于 2019-12-19 10:18:48
问题 I'm dealing with a legacy database table that has no insertion date column or unique id column, however the natural order of insertion is still valid when examined with a simple SELECT * showing oldest to newest. I'd like like to fetch that data with pagination but reverse the order as if it was ORDER BY date DESC I've thought about wrapping the query, assigning a numeric id to the resulting rows and then do an ORDER BY on the result but wow that seems crazy. Is there a more simple solution I