我有一個從整體 tableMysql的優化和爆炸
select
p, count(p) as frequency
from
(SELECT
id,
CASE power1 <= power2 WHEN TRUE THEN CONCAT(power1,"-",power2) ELSE CONCAT(power2,"-",power1)
END p
FROM power
UNION
SELECT
id,
CASE power1<=power3 WHEN TRUE THEN CONCAT(power1,"-",power3) ELSE CONCAT(power3,"-",power1) END p
FROM power
UNION
SELECT
id,
CASE power1<=power4 WHEN TRUE THEN CONCAT(power1,"-",power4) ELSE CONCAT(power4,"-",power1) END p
FROM power
UNION
...............................................
SELECT
id,
CASE power19<=power20 WHEN TRUE THEN CONCAT(power19,"-",power20) ELSE CONCAT(power20,"-",power19)
END p
FROM power) as b
group by
p
order by
frequency desc, p asc
limit
0, 10
顯示十大最拉數對下面的查詢我怎樣才能加以限制採取只是第100行按ID降序排列?該查詢會是這樣:
ORDER BY ID LIMIT 0,100
但我一直沒能適應它的上面。
代碼可以優化嗎?
power1,power2是表中的值....如果我有一個類似於3,4,5,6的字符串然後爆炸「,」,然後power1變成3,power2變成4等?
我指的是表格式是這個樣子:
以後編輯:
我的表是這樣的:
表:data
+----+----+-----+
| id | nr | set |
+----+----+-----+
| 1 | 52 | 1 |
| 2 | 47 | 1 |
| 3 | 4 | 1 |
| 4 | 3 | 1 |
| 5 | 77 | 1 |
| 6 | 71 | 1 |
| 7 | 6 | 1 |
| 8 | 41 | 1 |
| 9 | 15 | 1 |
| 10 | 79 | 1 |
| 11 | 35 | 2 |
| 12 | 50 | 2 |
| 13 | 16 | 2 |
| 14 | 1 | 2 |
| 15 | 32 | 2 |
| 16 | 77 | 2 |
| 17 | 30 | 2 |
| 18 | 7 | 2 |
| 19 | 20 | 2 |
| 20 | 28 | 2 |
| .. | .. | ... |
+----+----+-----+
我有一個像34360 ID
而下面的查詢:
SELECT
`n1`.`nr` AS `num_1`,
`n2`.`nr` AS `num_2`,
COUNT(1) AS `total`
FROM (select * from data ORDER BY id DESC limit 0,1000) AS `n1`
JOIN `data` AS `n2`
ON `n1`.`set` = `n2`.`set` AND `n1`.`nr` < `n2`.`nr`
GROUP BY `n1`.`nr`, `n2`.`nr`
ORDER BY `total` DESC
LIMIT 20
而且工作正常!
我想知道我怎麼能找出最長時間都沒有繪製在一起的數字對。每例如:
- 1,42(一起,作爲一對)尚未繪製24繪製
- 32,45-AS以及-尚未繪製22的一對平
- 等
表面上,這裏有太多的錯誤,我不知道從哪裏開始。但正常化不是一個很好的開始。 – Strawberry
正常化......這樣? http://i.stack.imgur.com/OsfKm.png – Xander
不是。這與正常化相反。 – Strawberry