我有一個fb_requests表。 Sql select count with count
我想選擇基於accept_status的game_selected列,如果accept_status數爲< 4,我想選擇那些行。努力工作,請幫我解決這個問題。
這是我創建嘗試這種代碼表的代碼
CREATE TABLE `fb_requests` (
`id` int(60) NOT NULL AUTO_INCREMENT,
`user_id` int(60) DEFAULT NULL,
`fb_user_id` varchar(255) DEFAULT NULL,
`request_id` varchar(255) DEFAULT NULL,
`game_selected` int(60) DEFAULT NULL,
`accept_status` int(60) DEFAULT NULL COMMENT '0 = pending 1 = accept',
`created_date` datetime DEFAULT NULL,
`modified_date` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=190 DEFAULT CHARSET=latin1
。我知道它在語法上不正確,但嘗試過。
Select
game_selected
from
fb_requests
where
user_id = 17
&&
(
count(accept_status =1) < 4
)
group by
game_selected;
在此先感謝。
你想看什麼?請描述你想要達到的目標。 – PeterRing
作爲一般規則,CREATE TABLE代碼(發佈爲文本,省略了不相關的列)和一些帶示例數據的INSERT INTO查詢比數據圖片更有用,因爲它允許潛在的回答者真正測試查詢。 –
如果accept_status計數<4,我想選擇基於accept_status的game_selected列,您想要accept_status計數或accept_status = 1的行數? – grasshopper