sql-order-by

Order by is currently only supported on the clustered columns of the PRIMARY KEY

北慕城南 提交于 2019-12-13 01:24:02
问题 cassandra2.0.7 cql 3.1.1 CREATE TABLE playlists ( id uuid, song_order int, song_id uuid, title text, album text, artist text, PRIMARY KEY (id, song_order ) ); INSERT INTO playlists (id, song_order, song_id, title, artist, album) VALUES (62c36092-82a1-3a00-93d1-46196ee77204, 1, a3e64f8f-bd44-4f28-b8d9-6938726e34d4, 'La Grange', 'ZZ Top', 'Tres Hombres'); INSERT INTO playlists (id, song_order, song_id, title, artist, album) VALUES (62c36092-82a1-3a00-93d1-46196ee77204, 2, 8a172618-b121-4136

Optimizing MySQL ORDER BY on a calculation shared with WHERE

泄露秘密 提交于 2019-12-13 00:32:17
问题 I have a MySQL SELECT query that calculates a distance using Pythagoras in the WHERE clause to restrict results to a certain radius. I also use the exact same calculation in the ORDER BY clause to sort the results by smallest distance first. Does MySQL calculate the distance twice (once for the WHERE, and again for the ORDER BY)? If it does, how can I optimize the query so it is only calculated once (if possible at all)? 回答1: Does MySQL calculate the distance twice (once for the WHERE, and

Problem with Select Mysql Condition Group By Order

﹥>﹥吖頭↗ 提交于 2019-12-13 00:21:21
问题 Each service has different KPIs. These KPIs are ordered with the field order in the table checklist_has_kpi. I want a list of separate services ordered by the order assigned to the KPI. I have this query: SELECT s.serviceid, s.servicenameit, s.servicenameen FROM services s, kpi k, checklist_has_kpi chk WHERE s.serviceid=k.serviceid AND k.kpiid=chk.kpiid AND k.inreport='yes' AND chk.checklistid=61 GROUP BY s.serviceid ORDER BY chk.order ASC But it does not produce the result that I expect and

How to return ordered data from multiple records into one record in MySQL?

自古美人都是妖i 提交于 2019-12-12 23:00:11
问题 I have a MySQL database with a table of survey responses with three important fields (renamed for clarity): SURVEY_TAKER_ID, QUESTION_NUMBER, and RESPONSE. Assuming a 3-question survey as an example, it would look something like this: SURVEY_TAKER_ID | QUESTION_NUMBER | RESPONSE ---------------------------------------- 101 1 Apple 102 1 Orange 103 1 Banana 101 2 Morning 102 2 Evening 103 2 Afternoon 101 3 Red 102 3 Blue 103 3 Yellow I would like to create a SELECT query that outputs each

How can I sort by multiple columns but not by value?

爱⌒轻易说出口 提交于 2019-12-12 20:14:49
问题 Question title might be a bit vague, so feel free to change it into something that makes more sense, I just couldn't find the right words. So here is my problem: In my table there are 2 important columns date_added (a datetime value) special_price (numeric) special_price is either NULL or a numeric value depending on what the special price is. I'll describe the way I want to order my result now: First I want to see all the items with no special_price ( NULL ) ordered by date (newest first),

ORDER BY function not working in Oracle

回眸只為那壹抹淺笑 提交于 2019-12-12 19:15:24
问题 I'm using the ORDER BY function as per below to order a simple query by customer id (it was originally party age but that didn't seem to work so I changed it to see if it was the syntax or not). SELECT customer_id, customer_name, party_age FROM customer ORDER BY customer_id The report returns no errors, but when I go to view the report it is not ordered at all. I have tried this using numbers as well (ORDER BY x). Anyone guide me in the right direction? EDIT: Customer_id is VARCHAR2(3) with

How to order by in Rails?

情到浓时终转凉″ 提交于 2019-12-12 19:13:15
问题 I'm working on a small blog engine. There are the following tables: Blog and Message. Blog has a foreign key: last_message_id, so I access the last message in the blog by calling blog.last_message I have the following code to make it work: class Blog < ActiveRecord::Base belongs_to :last_message, :class_name => "Message" end I need to order the blogs by the last messages. But when I call blogs.order("last_message.created_at DESC") It doesn't work. I get the following error: PGError: ERROR:

LINQ, Skip, OrderBy, and SQL Server 2000

若如初见. 提交于 2019-12-12 18:31:15
问题 I'm accessing a data context object that is auto-generated by using LINQ to SQL. The SQL database is a SQL Server 2000 box. The class I'm working with is a SQL View. I have a statement that is similar to this: query = _context.OrderDetails .Where(w => w.Product == "TEST") .OrderBy(o => o.DateCompleted) .ThenBy(t => t.LineItemId) .Skip(startRowIndex) .Take(maximumRows); However, when the value of Skip is anything but 0, I get this error: This provider supports Skip() only over ordered queries

MySQL Query - recent entries per group

佐手、 提交于 2019-12-12 16:55:44
问题 I'm trying to select the most recent entries per group in a table. Say I have a table "blog_posts" which has a column for "id" (all unique, auto incremented), "post_cat" which can be values 'category1' or 'category2' or 'category3', and a "publish_status" column which can be values 'online' or 'offline'. How can I select the most recent entries for each category? I have the following right now, but it almost feels like it's selecting randomly: select * FROM `blog_posts` WHERE (publish_status

How to make ORDER SIBLINGS BY?

家住魔仙堡 提交于 2019-12-12 14:27:06
问题 I'm using PostgreSQL 9.1.6 and trying to build recursive SQL. I want to sort like ORDER SIBLINGS BY in SQL-Server does it. Editor's note: This is probably supposed to refer to Oracle , where ORDER SIBLINGS BY actually exists. Test table: create table RECURSIVE_TEST( EMP_ID int, MANAGER_ID int, EMP_NAME varchar(30) ); insert into recursive_test values (1 ,0 ,'MANAGER1'), (2 ,0 ,'MANAGER2'), (3 ,0 ,'MANAGER3'), (4 ,0 ,'MANAGER4'), (5 ,1 ,'emp1'), (6 ,3 ,'emp2'), (7 ,4 ,'emp3'), (8 ,2 ,'emp4'),