sql-order-by

How to avoid OrderBy - memory usage problems

百般思念 提交于 2021-02-07 04:54:05
问题 Let's assume we have a large list of points List<Point> pointList (already stored in memory) where each Point contains X, Y, and Z coordinate. Now, I would like to select for example N% of points with biggest Z-values of all points stored in pointList . Right now I'm doing it like that: N = 0.05; // selecting only 5% of points double cutoffValue = pointList .OrderBy(p=> p.Z) // First bottleneck - creates sorted copy of all data .ElementAt((int) pointList.Count * (1 - N)).Z; List<Point>

How do I order groups by each group's highest value

╄→гoц情女王★ 提交于 2021-02-05 12:14:19
问题 I have data: query url score a www.google.com 3 a www.facebook.com 2 a www.google.com 1 I want to 'group' entries by their domain, and then order (desc) the domain groups by each group's highest score so I get: query url score a www.google.com 3 a www.google.com 1 a www.facebook.com 2 Trying: select * from table order by score desc, url asc doesnt work. It gives (no apparent change): query url score a www.google.com 3 a www.facebook.com 2 a www.google.com 1 回答1: You can use window functions -

How to order values in ascending order from MySQL query with PHP?

让人想犯罪 __ 提交于 2021-02-05 10:37:25
问题 I am using the following PHP script to grab and alter data from a MySQL table and print the results in a HTML table. I was hoping to order the data in ascending order by the $utilization_percentage variable, which is created by $total_client_time / $total_available_time * 100 . This occurs after the $sql query, so I am wondering if this can be accomplished with PHP? Or is there a way to alter the MySQL query to have the $utilization_percentage calculated within the query and then I can run a

How Order by Case in LINQ

て烟熏妆下的殇ゞ 提交于 2021-02-05 08:41:53
问题 I have this answer Entity framework OrderBy "CASE WHEN" but this only handle two options var p = ctx.People.OrderBy(p => (p.IsQualityNetwork == 1 || p.IsEmployee == 1) ? 0 : 1) .ThenBy(p => p.Name); I have a text field and want rows appear on an specific order. In sql I would do: ORDER BY CASE when name = "ca" then 1 when name = "po" then 2 when name = "pe" then 3 when name = "ps" then 4 when name = "st" then 5 when name = "mu" then 6 END 回答1: How about creating a map of your sort order? var

How Order by Case in LINQ

故事扮演 提交于 2021-02-05 08:41:29
问题 I have this answer Entity framework OrderBy "CASE WHEN" but this only handle two options var p = ctx.People.OrderBy(p => (p.IsQualityNetwork == 1 || p.IsEmployee == 1) ? 0 : 1) .ThenBy(p => p.Name); I have a text field and want rows appear on an specific order. In sql I would do: ORDER BY CASE when name = "ca" then 1 when name = "po" then 2 when name = "pe" then 3 when name = "ps" then 4 when name = "st" then 5 when name = "mu" then 6 END 回答1: How about creating a map of your sort order? var

linq->SQL orderby descending not working

巧了我就是萌 提交于 2021-02-04 16:27:29
问题 var Customer = (from c in DNAContextSQL.Customers where c.LastName != "" orderby c.PKID_Customer descending select new { c.PKID_Customer, c.OrganizationName, c.FirstName, c.LastName, c.Phone, c.Extension }).Distinct().ToList(); I know this is basic. I can't find any good reason why it's not working though. The queries sent to SQL Profiler don't seem to have an order by clause in them. Any ideas? I can get it to work with .OrderByDescending(...) but would like to know the reason behind this

Recursive Subquerying with sorting

↘锁芯ラ 提交于 2021-02-02 09:57:45
问题 I looked at Tim Hall's excellent article here, that allows you to work with self-referenced entities and show hierarchical data (starting with top level nodes and joining back recursively), using CTE like syntax in Oracle. So I have code that looks like this: WITH J1(JOBMST_ID, JOBMST_NAME, JOBMST_PRNTID, JOBMST_TYPE, LVL) AS ( SELECT JOBMST_ID, JOBMST_NAME, JOBMST_PRNTID, JOBMST_TYPE, 1 FROM TIDAL.JOBMST WHERE JOBMST_PRNTID IS NULL UNION ALL SELECT J2.JOBMST_ID,J2.JOBMST_NAME,J2.JOBMST

Recursive Subquerying with sorting

浪尽此生 提交于 2021-02-02 09:56:34
问题 I looked at Tim Hall's excellent article here, that allows you to work with self-referenced entities and show hierarchical data (starting with top level nodes and joining back recursively), using CTE like syntax in Oracle. So I have code that looks like this: WITH J1(JOBMST_ID, JOBMST_NAME, JOBMST_PRNTID, JOBMST_TYPE, LVL) AS ( SELECT JOBMST_ID, JOBMST_NAME, JOBMST_PRNTID, JOBMST_TYPE, 1 FROM TIDAL.JOBMST WHERE JOBMST_PRNTID IS NULL UNION ALL SELECT J2.JOBMST_ID,J2.JOBMST_NAME,J2.JOBMST

Different Default ordering between ORACLE and PostgreSQL

…衆ロ難τιáo~ 提交于 2021-01-29 13:17:46
问题 I have a simple ORACLE Query which I should rewrite it to be run on postgresql with same output as below Select X,Y FROM table_name order by Y in case of I have only the below data in the table Here you are the difference between PG and oracle in ordering the data Do you have idea why such this difference occurs? 回答1: Different Default ordering There is no such thing as "default ordering" - neither in Oracle nor in Postgres (or in any other relational database). Tables in a relational

Conditional order by clause

穿精又带淫゛_ 提交于 2021-01-29 10:32:25
问题 Below query returning error. Help me under the error and a way to achieve the conditional order by. I am trying to order by grade and name when grade >=8 and grade and marks when grade <8. SELECT name, grade, marks FROM students, grades WHERE min_mark <= marks AND marks <= max_mark AND marks >= 70 UNION SELECT TO_CHAR('NULL') AS name, grade, marks FROM students, grades WHERE min_mark <= marks AND marks <= max_mark AND marks <= 69 order by grade desc,(case when grade >= 8 then name when grade