【问题标题】:mysql row merge with LIMIT and where colosemysql 行与 LIMIT 合并,其中 colose
【发布时间】:2016-12-15 09:52:27
【问题描述】:

这是我名为 OS 的表,我需要下面提到的输出。

id  | os        |
-----------------
1   |windows XP |
2   |mac        |
3   |windows XP |
4   |windows Xp |
5   |linux      |
6   |mac        |
7   |Windows NT |
8   |linux      |
9   |Windows NT |
10  |mac        |
11  |linux      |
12  |mac        |
13  |windows XP |
14  |linux      |
15  |Windows NT |
16  |mac        |
17  |linux      |

我想从每个操作系统中获取两个 id,

任何人都可以提出 mysql 查询?

预期输出

1
3------------ windows xp
2
6------------mac
5
11----------linux
7
9----------windows NT

【问题讨论】:

  • 这个输出有什么关系?请为您想要的输出添加更具体的关系。

标签: mysql sql select row sql-order-by


【解决方案1】:
select * from 
(
    select min(id) as id, os from os_table group by os
    union 
    select max(id), os from os_table group by os
) tmp
order by os

如果您不需要特定顺序,则删除外部选择

【讨论】:

  • 我需要每个操作系统的两个 id。
  • 而我的查询结果不是你想要的,因为?
  • 谢谢亲爱的,我是一名java开发人员,而不是DB eng,所以我在sql方面很穷,我使用union得到了我的输出。谢谢,“工会是我的新知识”
猜你喜欢
  • 2013-06-05
  • 1970-01-01
  • 2014-01-09
  • 2020-08-19
  • 2014-07-27
  • 2014-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多