:SQLクエリ私は次のような結果をacheiveするために私を助けるSQLクエリを実行しようとしてい
----------------------------------------------------------------------------
| RowNum | email | point_1 | point_2 | total_point |
----------------------------------------------------------------------------
| 1 | [email protected] | 120 | 70 | 190 |
----------------------------------------------------------------------------
SQLクエリ文の1(ROWNUM、電子メールやpoint_1の値を取得します) :
$sql = "
select *
from
(
select ROW_NUMBER() OVER (ORDER BY m.first_name) as **RowNum**,
ltrim(rtrim(m.email_addr)) AS **email**,
CAST(isnull(p.points_accumulated,'0') AS INT) AS **point_1**
FROM (select * from crm_member_list where coy_id='HSG' and mbr_id not in (select mbr_id from o2o_tmp_mbr_issues_exclude)) m
left join (select * from crm_member_points where coy_id='HSG') p
on p.mbr_id = m.mbr_id
where m.email_addr = '[email protected]'
and m.date BETWEEN '2016-08-01 00:00:00' AND '2016-08-31 23:59:00'
)sub where RowNum>? and RowNum<? order by RowNum";
SQLクエリ文の2(point_2の値を取得する):
$sql = "
select CAST(isnull(p.points_accumulated,'0') AS INT) AS **point_2**
FROM (select * from crm_member_list where coy_id='HSG' and mbr_id not in (select mbr_id from o2o_tmp_mbr_issues_exclude)) m
left join (select * from crm_member_points where coy_id='HSG') p
on p.mbr_id = m.mbr_id
where m.email_addr = '[email protected]'
and m.date BETWEEN '2016-09-01 00:00:00' AND '2016-09-30 23:59:00'";
私は2を組み合わせることを試みました結果を得るために上に示されたtatementsしかし、私は
"直接SQLを実行し、カーソルなし"のエラーを取得しています。
コンバインドコード:
$sql = "
select *
from
(
(select ROW_NUMBER() OVER (ORDER BY m.first_name) as **RowNum**,
ltrim(rtrim(m.email_addr)) AS **email**,
CAST(isnull(p.points_accumulated,'0') AS INT) AS **point_1**
FROM (select * from crm_member_list where coy_id='HSG' and mbr_id not in (select mbr_id from o2o_tmp_mbr_issues_exclude)) m
left join (select * from crm_member_points where coy_id='HSG') p
on p.mbr_id = m.mbr_id
where m.email_addr = '[email protected]'
and m.date BETWEEN '2016-08-01 00:00:00' AND '2016-08-31 23:59:00'),
(select CAST(isnull(p.points_accumulated,'0') AS INT) AS **point_2**
FROM (select * from crm_member_list where coy_id='HSG' and mbr_id not in (select mbr_id from o2o_tmp_mbr_issues_exclude)) m
left join (select * from crm_member_points where coy_id='HSG') p
on p.mbr_id = m.mbr_id
where m.email_addr = '[email protected]'
and m.date BETWEEN '2016-09-01 00:00:00' AND '2016-09-30 23:59:00'
)
)sub where RowNum>? and RowNum<? order by RowNum";
どのように私は上記のような結果を生成するクエリステートメントの両方を組み合わせて行くべきですか?そして、point_1とpoint_2の列を追加してtotal_point列を取得するにはどうすればよいですか?事前
これはmysqlではなく、 'row_number()'をサポートしていません。正しいDBMSにタグを付けてください。 – fancyPants