sql-order-by

MySQL order by problems

杀马特。学长 韩版系。学妹 提交于 2019-12-18 09:38:45
问题 I have the following codes.. echo "<form><center><input type=submit name=subs value='Submit'></center></form>"; $val=$_POST['resulta']; //this is from a textarea name='resulta' if (isset($_POST['subs'])) //from submit name='subs' { $aa=mysql_query("select max(reservno) as 'maxr' from reservation") or die(mysql_error()); //select maximum reservno $bb=mysql_fetch_array($aa); $cc=$bb['maxr']; $lines = explode("\n", $val); foreach ($lines as $line) { mysql_query("insert into location_list

mysql order by serialized data?

元气小坏坏 提交于 2019-12-18 09:20:52
问题 I need to query a single field and order it by serialized data, is that even possible? my table fields are: ********************************************* | meta_id | user_id | meta_key | meta_value | ********************************************* my query looks like this SELECT user_id FROM $wpdb->usermeta WHERE meta_key='ba_ur' which works fine but here things start to make no scene to me meta_value holds a serialized data for example a:2:{s:4:"data";s:9:"text text";s:6:"number";s:2:"22";}

How do I order by multiple columns in a SELECT query?

匆匆过客 提交于 2019-12-18 09:06:03
问题 I have a table of records like below int_record_id int_category_id str_name int_order bit_active 1 1 test1 2 1 2 1 test2 1 1 3 2 test3 1 1 1 3 test4 3 1 i want to select this record in a such a way that it should be sorted in the order of both int_category_id and int_order so the result should be like below int_record_id int_category_id str_name int_order bit_active 2 1 test2 1 1 1 1 test1 2 1 3 2 test3 1 1 4 3 test4 3 1 Does any one have an idea about its sql query, i have tried a lot i'm

Different behaviour in “order by” clause: Oracle vs. PostgreSQL

感情迁移 提交于 2019-12-18 08:57:11
问题 I have the following table (created and populated them in Oracle and PostgreSQL): > create table foo (a varchar(10)); I populated them with values, and order by clause is behaving differently in PostgreSQL and Oracle (I don't think versions are relevant to this question): Oracle: > select a, length(a) from foo order by a; A LENGTH(A) ---------- ---------- .1 2 01 2 1 1 1#0 3 1#1 3 1.0 3 1.1 3 10 2 11 2 9 rows selected. I get what I expect. .1 before 01 , since . is before 0 in ascii table.

MySQL order by (str to int)

你离开我真会死。 提交于 2019-12-18 07:57:28
问题 SELECT `01` FROM perf WHERE year = '2013' order by CAST(`01` AS INT) LIMIT 3 Column 01 has numeric values as varchar. I need to order top 3 of '01' as integer. Why doesn't this query working? Table like this; +----------------------+ | name | 01 | 02 | year| +----------------------+ |name1 | 90 |*** |2013 | +----------------------+ |name2 | 93 | 55 |2013 | +----------------------+ |name3 |*** | 78 |2013 | +----------------------+ Query should order by 01 (dismiss * ) and give names and values

MySQL order by (str to int)

那年仲夏 提交于 2019-12-18 07:56:59
问题 SELECT `01` FROM perf WHERE year = '2013' order by CAST(`01` AS INT) LIMIT 3 Column 01 has numeric values as varchar. I need to order top 3 of '01' as integer. Why doesn't this query working? Table like this; +----------------------+ | name | 01 | 02 | year| +----------------------+ |name1 | 90 |*** |2013 | +----------------------+ |name2 | 93 | 55 |2013 | +----------------------+ |name3 |*** | 78 |2013 | +----------------------+ Query should order by 01 (dismiss * ) and give names and values

Query Sqlite Database by specific/custom ordering?

怎甘沉沦 提交于 2019-12-18 07:14:39
问题 Let's say I got a table, something like this: ID | TITLE 1 | AAA 2 | BBB 3 | CCC 4 | DDD 5 | EEE ... ... I want to perform a query, using IN opeator, while preserving the order of the IN Arguments database.query("some_table", null, ID + " IN("+ idsStr+")", null, null, null, null); For example, if the query is "select from some_table where id in (4,1,5) ...(order by???)", I want that the returned cursor to be sorted as 4,1,5 Is it possible? how? 回答1: EDIT: Tested, works: SELECT * FROM books

JOIN, GROUP BY, ORDER BY

廉价感情. 提交于 2019-12-18 06:56:39
问题 The problem I first had with the following query was that the group by clause was performed before the order by : The saved.recipe_id column is an integer generated by UNIX_TIMESTAMP() SELECT saved.recipe_id, saved.`date`, user.user_id FROM saved JOIN user ON user.id = saved.user_id GROUP BY saved.recipe_id ORDER BY saved.`date` DESC So I tried all sorts of different possible solution with sub queries and other bs. In the end I ended up with trying out some different sub queries in the join

Order by Maximum condition match

你。 提交于 2019-12-18 05:56:37
问题 Please help me to create a select query which contains 10 'where' clause and the order should be like that: the results should be displayed in order of most keywords(where conditions) matched down to least matched. NOTE: all 10 condition are with "OR". Please help me to create this query. i am using ms-sql server 2005 Like: Select * from employee where empid in (1,2,4,332,434) or empname like 'raj%' or city = 'jodhpur' or salary >5000 In above query all those record which matches maximum

Mysql slow query: INNER JOIN + ORDER BY causes filesort

那年仲夏 提交于 2019-12-18 05:56:09
问题 I'm trying to optimize this query: SELECT `posts`.* FROM `posts` INNER JOIN `posts_tags` ON `posts`.id = `posts_tags`.post_id WHERE (((`posts_tags`.tag_id = 1))) ORDER BY posts.created_at DESC; The size of tables is 38k rows, and 31k and mysql uses "filesort" so it gets pretty slow. I tried to use different indexes, no luck. CREATE TABLE `posts` ( `id` int(11) NOT NULL auto_increment, `created_at` datetime default NULL, PRIMARY KEY (`id`), KEY `index_posts_on_created_at` (`created_at`), KEY