sql-order-by

mysql sort table and get row position

心已入冬 提交于 2019-12-08 10:10:35
I've got a problem in mysql, I have a table of ID and nubmer ... somthing like that ID -------- number 3 -------- 340 1 -------- 10 12 -------- 23 And now I would like to selecet by ID, let's say ID=3 and is there a way of saying what is the position of this row in sorted table? In this case, ID = 3 would have first position, cuase of highest value in number. ID=12 would have second position ... and so on. set @row_number:=0; select * from (select ID, @row_number:=@row_number+1 from your_table order by number desc) as row_to_return where ID=3; The above query can be change to replace ID to

Re-ordering divs with jQuery

谁都会走 提交于 2019-12-08 09:03:43
问题 Is it possible to re-order some divs with jQuery. I have few divs and I would like re-order them on page load according data-index number that is in divs. Now: <div class="score" data-index="3">3</div> <div class="score" data-index="2">2</div> <div class="score" data-index="1">1</div> <div class="score" data-index="4">4</div> What I want: <div class="score" data-index="1">1</div> <div class="score" data-index="2">2</div> <div class="score" data-index="3">3</div> <div class="score" data-index=

How to improve query performance with order by, group by and joins

回眸只為那壹抹淺笑 提交于 2019-12-08 08:32:48
问题 I Had a problem with order by when joins multiple tables which have millions of data. But I got solution as instead of join with distinct use of EXISTS will improve performance from the following question How to improve order by performance with joins in mysql SELECT `tracked_twitter` . *, COUNT( * ) AS twitterContentCount, retweet_count + favourite_count + reply_count AS engagement FROM `tracked_twitter` INNER JOIN `twitter_content` ON `tracked_twitter`.`id` = `twitter_content`.`tracked

Which row (in order by some column) in a table corresponds to a row in another table?

这一生的挚爱 提交于 2019-12-08 07:39:13
问题 I have two tables, as follows (simplified from actual): mysql> desc small_table; +-----------------+---------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------+---------------+------+-----+---------+-------+ | event_time | datetime | NO | | NULL | | | user_id | char(15) | NO | | NULL | | | other_data | int(11) | NO | MUL | NULL | | +-----------------+---------------+------+-----+---------+-------+ 3 rows in set (0.00 sec) mysql> desc

Using [0] or First() with LINQ OrderBy

我怕爱的太早我们不能终老 提交于 2019-12-08 07:33:53
问题 If I have a structure like this Albums - Album - Discs - Tracks and I want to order a collection of albums by the title of the first track on the first disc. Is there something similar to the following I could do (keeping in mind I need to use the OrderBy extension method that accepts a string)? albums.OrderBy("Discs[0].Tracks[0].Title") I need to be able to sort using a string expression thus the need to use the OrderBy method i.e. albums.OrderBy("Track[0].Title"). The reason for this is our

Why does added RAND() cause MySQL to overload?

喜你入骨 提交于 2019-12-08 06:13:16
问题 OK I have this query which gives me DISTINCT product_series, plus all the other fields in the table: SELECT pi.* FROM ( SELECT DISTINCT product_series FROM cart_product ) pd JOIN cart_product pi ON pi.product_id = ( SELECT product_id FROM cart_product po WHERE product_brand = "everlon" AND product_type = "'.$type.'" AND product_available = "yes" AND product_price_contact = "no" AND product_series != "" AND po.product_series = pd.product_series ORDER BY product_price LIMIT 1 ) ORDER BY product

Applying Where clause for Order by in SQL

自闭症网瘾萝莉.ら 提交于 2019-12-08 05:57:45
问题 Would like to sort the following data the way allows in the order of choice of keywords based on like clause: Data in table: EmpId EmpLotusNotes 10001 Amit B/India 20002 Bharat C/India 30003 Kyo Jun/Japan 40004 Jee Lee/China 50005 Xavier K/USA Data to be presented/sorted based on certain country order (Japan, China, India, USA): EmpId EmpLotusNotes 30003 Kyo Jun/Japan 40004 Jee Lee/China 10001 Amit B/India 20002 Bharat C/India 50005 Xavier K/USA Note: I cannot create another table that holds

How can I perform SQL ORDER BY exposure, focal and iso (in numeric not string)

倾然丶 夕夏残阳落幕 提交于 2019-12-08 05:40:30
问题 The columns for Exposure, Focal, and Iso are not being sorted properly. It seems like they are all being interpreted as strings and sorted as such. For example, if I sort Exposure down, the values can look like this: 1/800, 1/800, 1/800, 1/80, 1/675, 1/640, 1/60, 1/500 If I sort the Focal, it can look like this: 1.4, 1.4, 1.4, 14.0, 14.0, 1.3, 13.0, 1.2, 1.2, 12.0, 1.0, 10.0 and if I sort by ISO, it can look like this: 800, 800, 800, 80, 80, 640, 640, 60, 500, 500, 50 EDIT: My other question

Order by “count (columns not null)”

五迷三道 提交于 2019-12-08 02:55:50
问题 I'm looking at a way to order the MySQL results by a count of the columns where the value is not null. Therefore, [id] [1] [1] [0] [1] [1] = 4 [id] [0] [1] [1] [1] [0] = 3 [id] [0] [0] [0] [1] [1] = 2 [id] [1] [0] [0] [0] [0] = 1 In the above case I'm ignoring the ID column but in practice I wouldn't care. ID is always NOT NULL so adding it to count wouldn't change the results. Anyone have any idea on this that doesn't involve doing a PHP parse on the result into a new array? I'm trying to

LINQ: Order By Anonymous Type

僤鯓⒐⒋嵵緔 提交于 2019-12-08 02:49:30
问题 Hello I am using linq to fill a gridview with the information from an xml from codebehind. I would like to order my Grid according to one of my elements in the xml ("value element") but can't figure out how to do this. Any ideas? gvResourceEditor.DataSource = (From resElem In resourceElements.Elements("data") _ Select New With { _ .Key = resElem.Attribute("name").Value, _ .Value = HttpUtility.HtmlEncode(resElem.Element("value").Value), _ .Comment = If(resElem.Element("comment") IsNot Nothing,