sql-order-by

hibernate order by association

别来无恙 提交于 2019-12-03 06:22:32
I'm using Hibernate 3.2, and using criteria to build a query. I'd like to add and "order by" for a many-to-one association, but I don't see how that can be done. The Hibernate query would end up looking like this, I guess: select t1.a, t1.b, t1.c, t2.dd, t2.ee from t1 inner join t2 on t1.a = t2.aa order by t2.dd <-- need to add this I've tried criteria.addOrder("assnName.propertyName") but it doesn't work. I know it can be done for normal properties. Am I missing something? Ok, found the answer. I tried something that I didn't think would work, but to my surprise did. I was trying this:

Using distinct on a column and doing order by on another column gives an error

妖精的绣舞 提交于 2019-12-03 05:58:30
I have a table: abc_test with columns n_num, k_str. This query doesnt work: select distinct(n_num) from abc_test order by(k_str) But this one works: select n_num from abc_test order by(k_str) How do DISTINCT and ORDER BY keywords work internally that output of both the queries is changed? Abhishek Bhandari As far as i understood from your question . distinct :- means select a distinct(all selected values should be unique). order By :- simply means to order the selected rows as per your requirement . The problem in your first query is For example : I have a table ID name 01 a 02 b 03 c 04 d 04

SQL - How To Order Using Count From Another Table

雨燕双飞 提交于 2019-12-03 03:45:23
问题 1. Bloggers blogger_id 1 2 3 2. Posts post_from_blogger_id 1 1 1 2 2 3 As you can see blogger №1 posted more than the others and blogger №3 less. The question is how to build a query that selects all bloggers and sorts them by the number of their posts? 回答1: SELECT bloggers.*, COUNT(post_id) AS post_count FROM bloggers LEFT JOIN blogger_posts ON bloggers.blogger_id = blogger_posts.blogger_id GROUP BY bloggers.blogger_id ORDER BY post_count (Note: MySQL has special syntax that lets you GROUP

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

て烟熏妆下的殇ゞ 提交于 2019-12-03 03:29:13
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-to-many HQL query with the order-by clause? I though of passing the orderBy field name string to the

Linq OrderBy breaks with navigation property being null

*爱你&永不变心* 提交于 2019-12-03 02:34:33
Working with four tables. Users -> has basic user info including a userid and a departmentid (int) Groups -> basic group info including a groupid GroupsMembers -> table that has the relationship between a group and it's members, many to many relationship, so groupid and userid are the columns Departments -> basic department info including deptid I have a fk from the departmentid in the users table to the deparmtnet id in the departments table. FK from groups groupid to groupsmembers groupid FK from users userid to groupsmembers userid This allows the groups in the edmx to have a users

Datatable select method ORDER BY clause

半腔热情 提交于 2019-12-03 02:20:19
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 Have you tried using the DataTable.Select(filterExpression, sortExpression) method ? Use datatable.select("col1='test'","col1 ASC") Then before binding your data to the grid or

Sql Server query varchar data sort like int

 ̄綄美尐妖づ 提交于 2019-12-03 02:04:26
I have one table like CREATE TABLE table_name ( P_Id int, amount varchar(50) ) Data Like Id amount ---------- 1 2340 2 4568 3 10000 Now I want to sort table by amount but one problem is amount is varchar so it sort table like this Id amount ---------- 3 10000 1 2340 2 4568 but i want result like this Id amount ---------- 3 10000 2 4568 1 2340 what should i do ? Cast amount column into Numeric in ORDER BY clause while selecting: SELECT * FROM MyTable ORDER BY CAST(amount AS Numeric(10,0)) DESC Result: ╔════╦════════╗ ║ ID ║ AMOUNT ║ ╠════╬════════╣ ║ 3 ║ 10000 ║ ║ 2 ║ 4568 ║ ║ 1 ║ 2340 ║ ╚════╩

how to customize `show processlist` in mysql?

放肆的年华 提交于 2019-12-03 00:04:31
问题 I want to order by Time,but seems no way to do that ? mysql> show processlist; +--------+-------------+--------------------+------+---------+--------+----------------------------------+------------------------------------------------------------------------------------------------------+ | Id | User | Host | db | Command | Time | State | Info | +--------+-------------+--------------------+------+---------+--------+----------------------------------+--------------------------------------------

Attempting to order table multiple times

半世苍凉 提交于 2019-12-02 23:45:28
问题 I am trying to group multiple rows and order it by the total values but im struggling to figure out whats going wrong. Name Total ======= ======= ASOS 222 Tesco 11 ASOS 11111 Tesco 123 The table should look like this Name Total ======= ======= ASOS 11111 ASOS 222 Tesco 123 Tesco 11 I thought this query would work select * from tablename order by name asc, total asc But that shows a result in the wrong order. Any help would be appreciated. 回答1: Try this select * from tablename order by total

TSQL ORDER BY with nulls first or last (at bottom or top)

二次信任 提交于 2019-12-02 22:18:14
I have a date column which has some NULL . I want to order by the date column ASC, but I need the NULL s to be at the bottom. How to do it on TSQL ? In standard SQL you can specify where to put nulls: order by col asc nulls first order by col asc nulls last order by col desc nulls first order by col desc nulls last but T-SQL doesn't comply with the standard here. The order of NULLs depends on whether you sort ascending or descending in T-SQL: order by col asc -- implies nulls first order by col desc -- implies nulls last With integers you could simply sort by the negatives: order by -col asc -