0
に参加し、私は、これらの3つのテーブル(これらの構造を持つ)を持つ:MYSQLクエリを選択&
outreach
id url profile_id
------------------------------------------
40 www.google.com 2
41 www.yahoo.com 3
42 www.test.com 1
outreach_links
id outreach_id end_date status
-----------------------------------------------
1 41 2016-01-12 Pending
2 40 2016-03-12 Pending
3 40 2016-02-12 Approved
comments
id outreach_id name
----------------------------
1 40
2 40
3 40
を、私はこのクエリを持っている:
select o.*,
SUM(if(ol.status = "Approved" and (ol.end_date > now() or end_date is null), 1, 0)) as cond1,
SUM(if(ol.status = "Pending" and (ol.end_date != now() or end_date is null), 1, 0)) as cond2,
SUM(if(ol.status = "Pending" and (ol.end_date < now()), 1, 0)) as cond3
from outreach o
left join outreach_links ol on ol.outreach_id = o.id
where o.profile_id=2
group by o.id
having (cond1 = 0 and cond2 = 0) or (cond1 = 0 and (cond2 = 1 and cond3 >=1)) order by ol.end_date desc
私はこのクエリを修正して作るしようとしています次の項目も選択します。
1). ol.* ONLY if MAX(end_date) and
2). Count(id.comment) count all comments for that particular row
は可能ですか?ここで今
が出力
+"id": "40"
+"profile_id": "2"
+"url": "http://www.google.com"
+"created_at": "2016-12-05 21:55:10"
+"updated_at": "2016-12-05 22:49:56"
+"cond1": "0"
+"cond2": "0"
+"cond3": "5"
である私は
+"max_date": get me max of end_date and the whole row of the row highlighted
+"Count(comments)": get me all the comments count for this one which is 3
おかげ
誰かがロジックCOND1、COND2と3 >> http://stackoverflow.com/questions/41113660/multiple-not-exsits-in-mysql-to-check-count-ofを説明し、ここでこの私を助けましたそれをチェックアウトしますが、max end_dateとコメント数を選択するためにそれを拡張する必要があります – user3150060