MYSQL 查询问题搜索
已经读了几天了,似乎无法解决我的问题。
让我深入了解我的数据库:
table1代码:
id CODE
1 D0G08H13L12
2 D1G12H10L12
3 D0G10H12L11
4 D1G10H10L09
5 D0G08H13L12
6 D1G12H10L12
7 D0G08H13L12
8 D1G10H10L09
9 D0G08H13L12
10 D1G12H10L12
现在我正在搜索一个查询来计算在D0G08H13L12之后出现次数最多的代码,因此在下一条记录中搜索我的查询答案将是:
3 times D1G12H10L12
1 time D1G10H10L09
这就是我所拥有的到目前为止,我认为我必须使用子查询,但我不太确定。
SELECT id, code, COUNT(code) FROM table1 WHERE id IN ($idprint +1) GROUP BY code
ORDER BY COUNT(code) DESC
你们中的任何 DB 专业人士都可以帮助我朝好的方向发展吗?
Have been reading for a few days now and can't seem to get hold of my problem here.
Let me give you an insight of my DB:
table1 codes:
id CODE
1 D0G08H13L12
2 D1G12H10L12
3 D0G10H12L11
4 D1G10H10L09
5 D0G08H13L12
6 D1G12H10L12
7 D0G08H13L12
8 D1G10H10L09
9 D0G08H13L12
10 D1G12H10L12
now I'm searching for a query to count which codes occurs the most after D0G08H13L12, so searching in the next record my answer from the query would be:
3 times D1G12H10L12
1 time D1G10H10L09
this is what I have until now, I think I have to use subquery but I'm not quite sure.
SELECT id, code, COUNT(code) FROM table1 WHERE id IN ($idprint +1) GROUP BY code
ORDER BY COUNT(code) DESC
can any of you DB pro's help me in the good direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
如果您只想有两条记录,请将其附加到查询中:
Try this:
If you want to have only two records append this to the query:
试试这个,这会给你想要的结果......
Try this, This will give u the desired result....
获取输入的最多下一个代码。
To get the most next codes for entered one.