sql-order-by

Django Using order_by with .annotate() and getting related field

╄→尐↘猪︶ㄣ 提交于 2019-12-24 03:07:09
问题 I have the following data, This query groups by topicid, and then in each group gets the max date, frequency of posts and counts the number of authors as contributors, info_model = InfoModel.objects.values('topicid') .annotate( max=Max('date'), freq=Count('postid'), contributors=Count('author', distinct=True)) This query can then be displayed as follows, Q.1 (SOLVED) How can I order the rows by date, from most recent down? I did appended .order_by('date') to the query, which seems like the

pagination sql query syntax

可紊 提交于 2019-12-24 02:13:32
问题 I am trying to sort my posts in my discussion board by date. Here is my code: $query = mysql_query("SELECT * FROM {$statement} LIMIT {$startpoint} , {$limit} ORDER BY datetime ASC"); Is there anything syntactically wrong with this? If not, what else could be wrong? Basically what is happening, is that the results are not showing up. I remove the Order by, and it works (but of course it's not sorted...) 回答1: Order by should go before limit: $query = mysql_query("SELECT * FROM {$statement}

Woocommerce: order by custom taxonomy

蓝咒 提交于 2019-12-24 02:07:38
问题 I'm having the following problem. I have set up a Wordpress site with WooCommerce to serve a webshop with only books. I have created some product attributes that are based on taxonomies like ' publisher ' and ' author ' (as multiple products can share an author or a publisher) I would like to be able to sort my products not only on the Woocommerce default fields like 'title' and 'price' but also on these taxonomy fields. Say for example: order by Author ASC or order by publisher DESC As far

SQL Get X last entries from a 'custom' post_type counting users individual number of custom post_type

你离开我真会死。 提交于 2019-12-24 02:07:14
问题 I would like, if possible to get in one query: The last 4 different users Excluding 'ID' = '1' WITH post_type = 'custom' Ordered by date or ID ( DESC ) Counting the total number of 'custom' post_type for each user (COUNT()) Here is a data example: Table Name: 'post' ID | user | Date | title | status | post_type | | | | | "2785" | "1" | "2016-05-24 18:49:15" | "Title" | "published" | "page_post" "2783" | "5" | "2016-05-24 11:24:08" | "Title" | "published" | "custom" "2781" | "1" | "2016-05-18

Oracle order by different

走远了吗. 提交于 2019-12-24 01:15:36
问题 I have a table in an Oracle Database like this ID | LABEL ------------ 1 | label alpha 1 2 | label alpha 2 3 | label alpha a when I do a select in an application like Squirrel like this : select * FROM MA_TABLE order by LABEL asc I get : ID | LABEL ------------ 1 | label alpha 1 2 | label alpha 2 3 | label alpha a which is fine ! but When I execute the same request using MyBatis : <select id="selectMaTable" resultMap="resultMap" > Select * FROM MA_TABLE order by LABEL asc </select> I get : ID

Order ul list by span content

余生长醉 提交于 2019-12-24 00:55:48
问题 I am really lost with trying to order an ul list by the span in the li. I have this next structure <ul id="videosList"> <li class="response1"> <a href="link"><img src="moon" /><span>Alex breaking bad</span> <li> <li class="response1"> <a href="link"><img src="moon" /><span>Jason playing piano</span> <li> <li class="response1"> <a href="link"><img src="moon" /><span>Jenny skying</span> <li> <li class="response1"> <a href="link"><img src="moon" /><span>Chuck norris</span> <li> <li class=

Does sqoop preserves order of imported rows as in Database

非 Y 不嫁゛ 提交于 2019-12-24 00:23:22
问题 I am sqooping a table from oracle database to AWS S3 & then creating a hive table over it. After importing the data, is the order of records present in database preserved in hive table? I want to fetch few hundred rows from database as well as hive using java JDBC then compare each row present in ResultSet . Assuming I don't have a primary key, can I compare the rows from both ResultSets as they appear(sequentially, using resultSet.next() ) or does the order gets changed due to parallel

Ordering dot-delimited numeric sequences (e.g., version numbers)

淺唱寂寞╮ 提交于 2019-12-23 21:47:20
问题 In my database I've column fill this data: 1 1.1 1.1.1 1.1.1.1 1.1.2 1.10 1.11 1.2 1.9 I want to sort it, to get result looks like this: 1 1.1 1.1.1 1.1.1.1 1.1.2 1.2 1.9 1.10 1.11 How can I accomplish this? Simple use "ORDER BY" gives wrong result because it's lexicographic order. 回答1: You could split the string to an array, cast it to an int[] and rely on Postgres' natural ordering for arrays: SELECT mycolumn FROM mytable ORDER BY STRING_TO_ARRAY(mycolumn, '.')::int[] ASC 回答2: Casting to

sort result of sql query by order of field in where clause of query

拥有回忆 提交于 2019-12-23 21:18:24
问题 I want to sort the result of this query according to the contains of the query : here it is : SELECT a from Frais a where a.libelle = 'FRET' or a.libelle = 'Douane' or a.libelle = 'Transitaire' I would like to have the records that have FRET first and Douane after and so on order by libelle doesn't resolve the problem it sort them according to alphabetic order asc or desc 回答1: SELECT a from Frais a where a.libelle = 'FRET' or a.libelle = 'Douane' or a.libelle = 'Transitaire' order by case a

MySQL ORDER BY FIELD with %

柔情痞子 提交于 2019-12-23 20:35:53
问题 I am trying to make an ORDER BY FIELD work with a wildcard, and have been unsuccessful: SELECT positions.*, departments.dept_name, departments.dept_url, divisions.dept_name AS div_name FROM positions LEFT JOIN departments ON positions.colleague_dept_code = departments.colleague_code LEFT JOIN departments AS divisions ON positions.colleague_div_code = divisions.colleague_code WHERE colleague_id = '$colleague_id' ORDER BY FIELD(positions.colleague_position_id, 'A%', 'F%', 'T%', 'S%', 'C%') The