sql-order-by

jpa2 CriteriaBuilder order by “ORDER BY expressions must appear in select list”

心已入冬 提交于 2019-12-10 21:08:19
问题 I'm writing a query with CriteriaBuilder , but it has not been possible to add the order by clause, because an error it's thrown with the message ORDER BY expressions must appear in select list this are my entities. public class A{ Integer aId; @ManyToOne @JoinColumn(name = "bId", nullable = false) B classB; //setter and getter. } public class B{ Integer bId; String name; //setter and getter. } my query look like this. CriteriaBuilder cb = super.getEntityManager().getCriteriaBuilder();

Order by relationship properties neo4j

本小妞迷上赌 提交于 2019-12-10 20:54:29
问题 Using Neo4j 1.9.3 - I want to create a music program listing. On a given program there may be three pieces being performed. Each piece has a composer associated with them, and may appear on many different programs, so I can't put sequence numbers on the piece nodes. I assume I can create the program, with relationships to each piece like so: (program1)-[:PROGRAM_PIECE {program_seq: 1}]->(piece1) (program1)-[:PROGRAM_PIECE {program_seq: 2}]->(piece2) (program1)-[:PROGRAM_PIECE {program_seq: 3}

Dynamic Linq & ICompare

社会主义新天地 提交于 2019-12-10 20:44:08
问题 I'm trying to make use of James McCormack's guide to using a custom IComparer with Dynamic Linq. - see http://zootfroot.blogspot.co.uk/2009/10/dynamic-linq-orderby.html?showComment=1347276236930#c11348033278810583 I use a query to pull back an Enumerable of string values: .Select("fieldname").Distinct() Then try to use .OrderBy(item=>item.GetReflectedPropertyValue("fieldname"),new myComparer()) GetReflectedPropertyValue is a helper method defined by James as public static string

SQL Custom Order By Clause

十年热恋 提交于 2019-12-10 20:16:04
问题 A quick Question. I have a query that brings back 2 columns 'Description' and 'Amount' In the Description we have 3 outcomes. 'Gold - owned', 'Bronze - no land' and 'Silver - identified / offered' I would like the result to show in an order of Gold,Silver,Bronze Order By Asc or Desc does not achieve this. Is there a way to customize a Order by clause? Any Help on this Would be appreciated thanks Rusty 回答1: Inside of a CASE , you may ascribe a numeric value to each and order those ascending.

Dynamic ORDER BY and ASC / DESC in a plpgsql function

不羁的心 提交于 2019-12-10 19:56:39
问题 Following the approach mentioned in this link, I want to pass ORDER BY and sorting order to a function dynamically. ORDER BY is working fine but I am not able to pass sorting order ( ASC / DESC ). What I have now: CREATE OR REPLACE FUNCTION list(_limit integer,_offset integer,sort_by varchar(100), _order varchar(100),_category varchar(100)) RETURNS TABLE( id INTEGER, name VARCHAR, clientname VARCHAR, totalcount BIGINT ) AS $$ DECLARE empty text := ''; BEGIN RETURN Query EXECUTE 'SELECT d.id,

PostgreSQL division by zero when ordering

依然范特西╮ 提交于 2019-12-10 19:20:01
问题 i need to execute this query in postgres but i couldn't get rid of this error ERROR: division by zero SQL state: 22012 here is the query : select id,rates_sum,rates_count from tbl_node order by rates_sum/rates_count DESC; i know i can add a small value to the rates_count but i get inaccurate values . Is there a way to make the postgres ignore this error ,or using if statement to check zeros and replace them with any number. and again the error in the order by clause. Thanks 回答1: Use a CASE

Select unique rows, according to value in a secondary column

感情迁移 提交于 2019-12-10 19:19:54
问题 I have a simple mysql table: id, code, product_name, supplier 1, 3844, ProductName1, Supplier1 2, 3844, ProductName1, Supplier2 3, 1233, ProductName2, Supplier2 I want to query all distinct products from table. So sql code is select * from table group by code . My problem : I want to set supplier priority in "group by" statement (e.g. Supplier1 is most relevant, but can be absent in list for a given code ). Products #1 and #2 are the same. In my resulting table I want to see: id, code,

Combining two SQL SELECT statements on the same table

我怕爱的太早我们不能终老 提交于 2019-12-10 19:19:35
问题 I would like to combine these two SQL queries: SELECT * FROM "Contracts" WHERE "productType" = 'RINsell' AND "clearTime" IS NULL AND "holdTime" IS NOT NULL ORDER BY "generationTime"; and SELECT * FROM "Contracts" WHERE "productType" = 'RINsell' AND "clearTime" IS NULL AND "holdTime" IS NULL ORDER BY "contractLimitPrice"; When I run each statement, I get exactly the results I want, I would just like both results sequentially. My first thought was to use UNION ALL since this selections will be

Rails Active Admin how to config.sort_order with 2 columns (1 column from association)

别来无恙 提交于 2019-12-10 17:37:13
问题 In Active Admin would like to know how to setup config.sort_order with 2 columns where first column is come from same model and second column is from associated model? ActiveAdmin.register Race do menu parent: :races, :label => proc{ I18n.t('activerecord.models.races') } belongs_to :meeting, :optional => true #need to order by "meetings.date desc races.time desc" config.sort_order = "?" controller do def scoped_collection end_of_association_chain.includes(:meeting) end end end 回答1: config

ORDER BY id or date_created to show latest results?

半世苍凉 提交于 2019-12-10 17:36:38
问题 I have a table (several actually) that I want to get results from with the most recent entries first. Here are my ORDER BY clause options: date_created INT (never changes value) id (INT AUTO_INCREMENT of course!) Both columns should equally represent the order in which the records were inserted. I naturally would use the date_created field like any sane person would, but I'm still curious about this. I know this is probably splitting hairs, but is there any reason or edge case why I should