我試圖將幾個SQL調用壓縮成一個,並想知道如果以下是可能的。SQL調用返回天數與多日項目的月份
這裏是我的表格。
Organization
id
Event
id,
startDate
endDate
FavoriteOrgs
userId
orgId
對於一個月中的每一天,我想回到那一天發生的事件的計數。不要太難,直到您添加事實事件可以跨度2或3天。
以下是迄今爲止我能夠準確地顯示日事件次數的內容,但它僅包含事件的計數,以便它開始的那一天。
SELECT DAYOFMONTH(CAST(o.start_date AS DATE)) AS dayNum, COUNT(*) AS count
FROM favoriteOrgs f, event e, organization o
WHERE f.user_id =200372
AND e.profile_id = o.id AND e.profile_id = f.profile_id AND o.id = f.profile_id
AND e.last_date >= '$startDate'
AND e.start_date <= '$lastDate'
GROUP BY e.start_date
你可以發佈你的模式嗎 – hafichuk
我發佈了它的問題,但這裏又是:organization(id); event(id,startDate,endDate); favoriteOrgs(userId,orgId) –
那不是一個模式。我不知道那是什麼。在您的mysql客戶端運行「DESC組織」等。請參閱http://dev.mysql.com/doc/refman/5.0/en/describe.html。 – hafichuk