CREATE TABLE `EventList` (
`GroupID` int(11) NOT NULL ,
`eventID` int(11) NOT NULL ,
`EMPNAME` varchar(20) NOT NULL,
`EMPAGE` int(11) NOT NULL,
`SALARY` bigint(20) NOT NULL,
`ADDRESS` varchar(20) NOT NULL,
`empaddress` varchar(255) DEFAULT NULL,
`file_data` tinyblob
)
insert into eventlist(GroupID,eventID,EMPNAME,EMPAGE,SALARY,ADDRESS,empaddress,file_data) value (1,2,"anil",5,556,'del','del','//document')
insert into eventlist(GroupID,eventID,EMPNAME,EMPAGE,SALARY,ADDRESS,empaddress,file_data) value (1,5,"anil",5,556,'del','del','//document')
insert into eventlist(GroupID,eventID,EMPNAME,EMPAGE,SALARY,ADDRESS,empaddress,file_data) value (1,7,"anil",5,556,'del','del','//document')
insert into eventlist(GroupID,eventID,EMPNAME,EMPAGE,SALARY,ADDRESS,empaddress,file_data) value (1,8,"anil",5,556,'del','del','//document')
insert into eventlist(GroupID,eventID,EMPNAME,EMPAGE,SALARY,ADDRESS,empaddress,file_data) value (1,9,"anil",5,556,'del','del','//document')
insert into eventlist(GroupID,eventID,EMPNAME,EMPAGE,SALARY,ADDRESS,empaddress,file_data) value (2,15,"anil",5,556,'del','del','//document')
insert into eventlist(GroupID,eventID,EMPNAME,EMPAGE,SALARY,ADDRESS,empaddress,file_data) value (2,16,"anil",5,556,'del','del','//document')
insert into eventlist(GroupID,eventID,EMPNAME,EMPAGE,SALARY,ADDRESS,empaddress,file_data) value (3,19,"anil",5,556,'del','del','//document')
insert into eventlist(GroupID,eventID,EMPNAME,EMPAGE,SALARY,ADDRESS,empaddress,file_data) value (3,22,"anil",5,556,'del','del','//document')
insert into eventlist(GroupID,eventID,EMPNAME,EMPAGE,SALARY,ADDRESS,empaddress,file_data) value (3,24,"anil",5,556,'del','del','//document')
insert into eventlist(GroupID,eventID,EMPNAME,EMPAGE,SALARY,ADDRESS,empaddress,file_data) value (3,27,"anil",5,556,'del','del','//document')
insert into eventlist(GroupID,eventID,EMPNAME,EMPAGE,SALARY,ADDRESS,empaddress,file_data) value (3,29,"anil",5,556,'del','del','//document')
insert into eventlist(GroupID,eventID,EMPNAME,EMPAGE,SALARY,ADDRESS,empaddress,file_data) value (0,31,"anil",5,556,'del','del','//document')
insert into eventlist(GroupID,eventID,EMPNAME,EMPAGE,SALARY,ADDRESS,empaddress,file_data) value (0,32,"anil",5,556,'del','del','//document')
insert into eventlist(GroupID,eventID,EMPNAME,EMPAGE,SALARY,ADDRESS,empaddress,file_data) value (0,33,"anil",5,556,'del','del','//document')
insert into eventlist(GroupID,eventID,EMPNAME,EMPAGE,SALARY,ADDRESS,empaddress,file_data) value (0,34,"anil",5,556,'del','del','//document')
insert into eventlist(GroupID,eventID,EMPNAME,EMPAGE,SALARY,ADDRESS,empaddress,file_data) value (0,35,"anil",5,556,'del','del','//document')
insert into eventlist(GroupID,eventID,EMPNAME,EMPAGE,SALARY,ADDRESS,empaddress,file_data) value (0,36,"anil",5,556,'del','del','//document')
insert into eventlist(GroupID,eventID,EMPNAME,EMPAGE,SALARY,ADDRESS,empaddress,file_data) value (0,37,"anil",5,556,'del','del','//document')
insert into eventlist(GroupID,eventID,EMPNAME,EMPAGE,SALARY,ADDRESS,empaddress,file_data) value (0,39,"anil",5,556,'del','del','//document')
這是我的表結構查詢:如何獲取數據的頂部在MySQL 4的記錄
GroupID eventID EMPNAME EMPAGE SALARY ADDRESS empaddress file_data
1 2 anil 5 556 del del ...
1 5 anil 5 556 del del ...
1 7 anil 5 556 del del ...
1 8 anil 5 556 del del ...
1 2 anil 5 556 del del ...
2 15 anil 5 556 del del ...
2 16 anil 5 556 del del ...
3 19 anil 5 556 del del ...
3 22 anil 5 556 del del ...
3 24 anil 5 556 del del ...
3 27 anil 5 556 del del ...
3 29 anil 5 556 del del ...
0 31 anil 5 556 del del ...
0 32 anil 5 556 del del ...
0 33 anil 5 556 del del ...
0 34 anil 5 556 del del ...
0 35 anil 5 556 del del ...
0 36 anil 5 556 del del ...
0 37 anil 5 556 del del ...
目前的數據來的時候有寫這樣的查詢來獲取這樣每個組,我們必須取如果小於4事件則只我們獲取只有2記錄
輸出的願望,我想只有4事件
GroupID eventID EMPNAME EMPAGE SALARY ADDRESS empaddress ist
1 2 anil 5 556 del del ... 1
1 5 anil 5 556 del del ... 1
1 7 anil 5 556 del del ... 1
1 2 anil 5 556 del del ... 1
2 15 anil 5 556 del del ... 0
2 16 anil 5 556 del del ... 0
3 19 anil 5 556 del del ... 1
3 22 anil 5 556 del del ... 1
3 24 anil 5 556 del del ... 1
3 29 anil 5 556 del del ... 1
0 31 anil 5 556 del del ... 1
0 32 anil 5 556 del del ... 1
0 33 anil 5 556 del del ... 1
0 34 anil 5 556 del del ... 1
我想要這樣的記錄哪裏是如果特定組有超過4記錄那麼它應該是1 請建議我如何寫這個查詢,以便我可以得到這樣的輸出。正如我在評論中提到
@EhsanT我是confuesd如何從員工那裏EVENTID極限凌晨4時試圖寫得到這樣的輸出 –
選擇羣ID,事件ID查詢,EMPNAME \t,EMPAGE \t,薪金\t但是這不會工作 –
@EhsanT此查詢的任何解決方案? –