sql-order-by

Sort CSV file by column priority using the “sort” command

限于喜欢 提交于 2019-12-02 14:25:31
I have a csv file, and I would like to sort it by column priority, like "order by". For example: 3;1;2 1;3;2 1;2;3 2;3;1 2;1;3 3;2;1 If this situation was the result of a "select", the "order by" would be as follows: order by column2, column1, column3 - the result would be: 2;1;3 3;1;2 1;2;3 3;2;1 1;3;2 2;3;1 I'd like to know how to get this same result using "sort" command on Unix. sort --field-separator=';' --key=2,1,3 Charlie's answer above didn't work for me on Cygwin (sort version 2.0, GNU textutils), the following did: sort -t"," -k2 -k1 -k1 Suppose you have another row 3;10;3 in your

how to customize `show processlist` in mysql?

折月煮酒 提交于 2019-12-02 13:50:57
I want to order by Time,but seems no way to do that ? mysql> show processlist; +--------+-------------+--------------------+------+---------+--------+----------------------------------+------------------------------------------------------------------------------------------------------+ | Id | User | Host | db | Command | Time | State | Info | +--------+-------------+--------------------+------+---------+--------+----------------------------------+------------------------------------------------------------------------------------------------------+ | 1 | system user | | NULL | Connect |

Attempting to order table multiple times

孤街浪徒 提交于 2019-12-02 13:35:17
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. Try this select * from tablename order by total desc Selecting two things to ORDER BY doesn't work too well if you're not familiar with ORDER BY syntax. from

select sql data order by date

不羁的心 提交于 2019-12-02 13:31:50
I have a table with a column called date , as a varchar. The contents are specifically formatted like 'March 11, 2011'. How can I select the results have them correctly ordered by date? I'm blindly assuming MySQL here, because it makes sense in the context of this question. Nobody using another database engine would dare create this problem in the first place. STR_TO_DATE to the rescue! Given the format "March 01, 2000", the following conversion should work. SELECT STR_TO_DATE(column_name, '%M %d, %Y') FROM TableName WHERE ... ORDER BY STR_TO_DATE(column_name, '%M %d, %Y') You may need to

OrderBy not having any effect in LINQ

泪湿孤枕 提交于 2019-12-02 12:26:30
I have a table that has a set of data in it, as follows: Notice the above results are gathered by the following SQL query: select * from Logs where RegisterationId = 16 and date = '2018-04-13 00:00:00.000' order by DateTime ASC; Now this is perfect but when I try to do the same in LINQ using: var logs = db.Logs.Where(x => x.RegisterationId == EnrollNumber && x.Date >= StartDate && x.Date <= EndDate && x.isIgnore != true).OrderBy(x => x.DateTime).Distinct().ToList(); it gives all the Manual_Entry logs together at the bottom/at the end of the list (notice the index 15,16 & 17 in the snapshots

JPA @OrderBy() Through Relational Table

假如想象 提交于 2019-12-02 12:13:48
I need some help with the JPA Framework. I've read some answers "kind of" about this topic but I couldn't reach any conclusion. First heres an examplo of the design i'm wooking with. @BusinessObject public class ClassA { @Column(name = "ID", nullable = false) private Long id; @OneToMany(mappedBy = "classAAttr") private Collection<ClassAB> classABCollection; //STUFF AND OTHER COLUMNS..... } public class ClassAB { @Column(name = "ID", nullable = false) private Long id; @JoinColumn(name = "TABLE_A_ID", referencedColumnName = "ID") @ManyToOne private ClassA classAAttr; @JoinColumn(name = "TABLE_B

Can you sort Typed DataSet DataTables with Linq OrderBy?

天涯浪子 提交于 2019-12-02 11:47:54
I have a Typed DataSet DataTable which inherits TypedTableBase<T> , which in turn implements IEnumerable<T> . I can't seem to get this to work. myDataTable.OrderBy(x => x.ID).ThenBy(y => y.ID2); Instead I have to assign this statement to an IEnumerable (or List), then refill my DataTable manually with the newly ordered IEnumerable before I commit. Is this how it is intended to be? I've thought about creating my own extension method that will empty/refill my DataTables, but would this be wise? Note: Typically I only need to sort for viewing purposes using DataView. But in this case I have a

How to sum the duplicate values from mysql table

Deadly 提交于 2019-12-02 10:06:37
i wanted to retrieve the sum of duplicate USD amount from below table with respect to date and ref_nr columns uid date USD Ref_Nr 1 2018-04-11 1 7 1 2018-04-11 2 7 1 2018-04-11 3 8 1 2018-04-11 4 8 1 2018-04-11 6 6 1 2018-04-11 6 6 1 2018-04-10 3 7 1 2018-04-10 5 7 1 2018-04-10 2 8 1 2018-04-10 2 8 Here is my sql query and what i tried, but iam not getting proper output, please help me SELECT uid , date , SUM(USD) AS USD , Ref_Nr FROM my_table GROUP BY `date`; Here is expected output uid date USD Ref_Nr 1 2018-04-11 3 7 1 2018-04-11 7 8 1 2018-04-11 12 6 1 2018-04-10 8 7 1 2018-04-10 4 8

How Can I Make Oracle Query Sort Order Dynamic?

最后都变了- 提交于 2019-12-02 09:21:58
问题 I have a Oracle procedure inside a package like this PROCEDURE getEmployee ( pinLanguage IN VARCHAR2, pinPage IN NUMBER, pinPageSize IN NUMBER, pinSortColumn IN VARCHAR2, pinSortOrder IN VARCHAR2, poutEmployeeCursor OUT SYS_REFCURSOR ) AS BEGIN OPEN poutEmployeeCursor FOR SELECT * FROM ( SELECT EMPLOYEE_ID, USERNAME, FULL_NAME, DATE_OF_BIRTH, EMP.GENDER_ID, GEN_TR.GENDER, EMP.WORK_TYPE_ID, WT_TR.WORK_TYPE, SALARY, EMAIL, PROFILE_IMAGE, ROW_NUMBER() OVER (ORDER BY EMPLOYEE_ID ASC) RN FROM

mysql: how to save ORDER BY after LEFT JOIN without reorder?

旧城冷巷雨未停 提交于 2019-12-02 09:12:44
I've two table: 1) profiles +----+---------+ | id | name | +----+---------+ | 1 | WILLIAM | | 2 | JOHN | | 3 | ROBERT | | 4 | MICHAEL | | 5 | JAMES | | 6 | DAVID | | 7 | RICHARD | | 8 | CHARLES | | 9 | JOSEPH | | 10 | THOMAS | +----+---------+ 2) request_for_friendship +----+---------+-------+ | id | from_id | to_id | +----+---------+-------+ | 1 | 1 | 2 | | 2 | 1 | 3 | | 3 | 1 | 8 | | 5 | 4 | 1 | | 6 | 9 | 1 | +----+---------+-------+ I need to get all profiles with some sorting and join it with request_for_friendship For example, get all users with some sorting: mysql> SELECT * -> FROM