SELECT * FROM (
SELECT VD.`cat_id` ,
@cat_count := IF((@cat_id = VD.`cat_id`), @cat_count + 1, 1) AS 'DUMMY1',
@cat_id := VD.`cat_id` AS 'DUMMY2',
@cat_count AS 'CAT_COUNT'
FROM videos VD
INNER JOIN categories CT ON CT.`cat_id` = VD.`cat_id`
,(SELECT @cat_count :=1, @cat_id :=-1) AS CID
ORDER BY VD.`cat_id` ASC) AS `CAT_DETAILS`
WHERE `CAT_COUNT` < 4
------- STEP FOLLOW ----------
1 . select * from ('FILTER_DATA_HERE') WHERE 'COLUMN_COUNT_CONDITION_HERE'
2. 'FILTER_DATA_HERE'
1. pass 2 variable @cat_count=1 and @cat_id = -1
2. If (@cat_id "match" column_cat_id value)
Then @cat_count = @cat_count + 1
ELSE @cat_count = 1
3. SET @cat_id = column_cat_id
3. 'COLUMN_COUNT_CONDITION_HERE'
1. count_column < count_number
4. ' EXTRA THING '
1. If you want to execute more than one statement inside " if stmt "
2. IF(condition, stmt1 , stmt2)
1. stmt1 :- CONCAT(exp1, exp2, exp3)
2. stmt2 :- CONCAT(exp1, exp2, exp3)
3. Final "If" Stmt LIKE
1. IF (condition , CONCAT(exp1, exp2, exp3) , CONCAT(exp1, exp2, exp3))
share
運行完美,這就是我需要的 – AXheladini 2010-06-30 08:21:57
我可以從這個選擇創建視圖在某些方面,我嘗試,但它說:1349 - 視圖的SELECT語句包含在FROM子句中 – AXheladini 2010-06-30 09:04:51
@AXheladini子查詢:對不起,MySQL的贏不允許出於幾個原因 - 使用變量的子查詢... MySQL視圖受到極其嚴格的限制,我擔心 - 它們會在CREATE VIEW文檔中列出限制條件:http://dev.mysql.com/doc/ refman/5.1/en/create-view.html – 2010-06-30 15:04:19