有没有更简洁的方法在 MySQL 中编写以下代码,而不仅仅是在编程语言中使用循环?table_vw 有很多行和几列,第 s 列的值在 0 到 7 之间
table_vw
sth sth_else sth_else ...
7
.
.
6
.
.
5
.
.
4
.
.
3
.
.
2
.
.
1
.
.
0
.
.
(
SELECT *
FROM table_vw
WHERE sth = 7
LIMIT 12
)
UNION
(
SELECT *
FROM table_vw
WHERE sth = 6
LIMIT 12
)
UNION
(
SELECT *
FROM table_vw
WHERE sth = 5
LIMIT 12
)
UNION
(
SELECT *
FROM table_vw
WHERE sth = 4
LIMIT 12
)
UNION
(
SELECT *
FROM table_vw
WHERE sth = 3
LIMIT 12
)
UNION
(
SELECT *
FROM table_vw
WHERE sth = 2
LIMIT 12
)
UNION
(
SELECT *
FROM table_vw
WHERE sth = 1
LIMIT 12
)
UNION
(
SELECT *
FROM table_vw
WHERE sth = 0
LIMIT 12
)