In grouping nested query, the clause for ordering is invalid.
Expected behavior
I need to sum up the article of a contest on steemit. I need to search the last record of each group. In the inner nesting I plan to sort the records in descending order of the field "timestamp", and in the outer nesting I plan to group the records by "permlink". According to my expectations, I should get the recent record of each group.
Actual behavior
In order to test, I wrote four queries to compare. The first is a simple query:
SELECT * FROM sbds_tx_comments WHERE author = "tvb" AND permlink NOT LIKE 're%'AND TIMESTAMP > '2018-01-24 00:00:00'
The second is a simple query with ordering:
SELECT * FROM sbds_tx_comments WHERE author = "tvb" AND permlink NOT LIKE 're%'AND TIMESTAMP > '2018-01-24 00:00:00' ORDER BY TIMESTAMP DESC
The third is a nested query:
SELECT permlink, TIMESTAMP FROM ( SELECT * FROM sbds_tx_comments WHERE author = "tvb" AND permlink NOT LIKE 're%' AND TIMESTAMP > '2018-01-24 00:00:00' ORDER BY TIMESTAMP DESC)tmp GROUP BY permlink
The fourth is another nested query:
SELECT permlink, TIMESTAMP FROM ( SELECT * FROM sbds_tx_comments WHERE author = "tvb" AND permlink NOT LIKE 're%' AND TIMESTAMP > '2018-01-24 00:00:00' ORDER BY TIMESTAMP ASC)tmp GROUP BY permlink
How to reproduce
I will provide the screenshot for the results of these queries. The result of the first query is as below:
According to the picture, in the records whose "permlink" is equal to "laodr-or", the "timestamp" of the first record is "2018-01-25 09:53:42". The record is the first in the physical order of the table.
The result of the second query is as below:
In the picture, we can see that, in the records whose "permlink" is equal to "laodr-or", the timestamp" of the first record is "2018-01-26 05:15:57". That means the last modified version of the link "laodr-or" is at "2018-01-26 05:15:57".
Then let me show the result of the thrid query:
Aft
er grouping, the result should show the last record of each group, whose timestamp is max. But in the screenshot, we can see ,the first record whose "link" is "laodr-or" is at "2018-01-25 09:53:42", which is the same as the first query, not the second!
Let's watch the fourth:
The result is the same as the first and the third one.
In conclusion, in nested query, grouping after sorting, the ordering is invalid. In each group, the result the first record of the physical order of the table.
Chrome version 63 64bit
Win 10 64 bit
(Both of them are uninfluential in the bug.)
I tested the bug with phpMyAdmin - 2.11.9.2. Of course the bug still exists when I use php to connect the SBDS. And I have exported a few data to my local mysql database, there isn't the bug.
Posted on Utopian.io - Rewarding Open Source Contributors
哇,一姐整起来是杠杠的啊!
不知道这算不算bug呀,不过正常的mysql不应该这样,我还在等待utopian-io的宣判。
找justyy给你审啊,让他给你过一下
不能给我偶像添乱哈哈
这怎么叫添乱呢?!这叫创收!
他多通过一条,也多一份收入不是
我突然想到我还有一点需要解释一下,我修改一下。
好像不用。。。
我还希望有外国的偶像帮我审一下,还能我认识认识哈哈。幻想能涨个粉啥的哈哈哈哈。
论贪心,只能是我哈哈哈
Your contribution cannot be approved because it does not follow the Utopian Rules.
Hi this is not a bug. Your correct SQL should be
You can contact us on Discord.
[utopian-moderator]
优秀!!这样的人才!
我这还不一定能通过呢。。。。
我的妈,中文区都是程序猿!
我是伪程序员,你不要怕。
呃,竟然是程序员,我要快快躲起来,显得我水平太低...
伪程序员,你怕啥,我觉得你比我厉害呢
我也想伪一下,可是没有这个能力
你会的很多了,画画和设计这些都是需要很深的功力呢。我好羡慕你画画画得超好!
如果具备能力代理或者能力转让,那就好了。能力区块链
I have no idea what you're talking about, but I can assure you the problem is with me, not you. Great stuff!!!!
I have described it not very well.
You're English is getting very good, you are starting to defend yourself now 😉
defend myself?这是自我保护的意思?
可以解作自我保護,自辯,解釋。總之我覺得用外語 defend yourself, 代表你對自己外語開始有信心 👍👍👍
没有信心呀,这个utopian-io找bug要求必须用英语说明,我是勉强描述这个bug的。。。。
@tvb 很難接受別人讚美
我們要多讚美她
逆天了!!!开始全英文写作了啊!!!!厉害
我十分想写中文,问题是utopian不让呀。。。。我从上午11点写到现在。。。累屎了
不错不错,怎么感觉在这里要混不下去了,大家都是多面手,让我这种人怎么办?
我今天也在utopian上提交了一个WordPress的插件,希望帮支持一下。
https://steemit.com/utopian-io/@rileyge/wordpress-plugin-to-sync-wordpress-and-steemit-comments
我一共就发了这一篇呢,不像你那么厉害呢,我要向你学习,你是在一个方向上专业精!
不专也不精的,我的水平只是外行人觉得很厉害,和大神一比的话就原型毕露了。
给姐大赞!虽然也没多少,😄
谢谢啦,要是帮我看看我的英文表述我就更感激了哈哈,我有点不要脸是不是
百分百赞我好感动,谢谢妹妹!
我手动赞都是百分百,哈哈,姐有时候不是是因为把姐添到自动点赞了。为了能恢复一些,好持续点赞,才设置的比例,没有别的意思哦。:-)有时候在自动点赞前看到文章就手动点了。希望理解哈。
我没也没怎么注意过点赞其实,自从接受了 @dapeng的活动,精力都在活动上了。
姐辛苦啦!赞!
厉害了 T姐居然是程序媛
伪的。。我水平太初级了!