サブクエリの返す行数をクエリ自体で取得したいと思います。次に、ifの場合はメインのクエリで使用します。私は例を追加し、ダミー文字列としてQUERY_ROW_COUNTを配置しました。これを実現する関数はありますか?事前のおかげで...よろしく...mysqlクエリ自体の行数を取得
SELECT period_id,
lt_id,
period_name,
min_stay,
IF(QUERY_ROW_COUNT=1, 1,0) as tag
FROM (SELECT period_id,
lt_id,
period_name,
min_stay,
fromDate,
toDate,
DATEDIFF('2010-12-27', '2010-12-10') as totalDays,
nightly_rate,
case when ('2010-12-10' > fromDate AND '2010-12-27' < toDate) then
DATEDIFF('2010-12-27', '2010-12-10')
else 0
end as d6,
case when ('2010-12-10' > fromDate AND '2010-12-27' > toDate) then
DATEDIFF(toDate, '2010-12-10')+1
else 0
end as d7,
case when ('2010-12-10' < fromDate AND '2010-12-27' < toDate) then
DATEDIFF('2010-12-27', fromDate)
else 0
end as d8,
case when ('2010-12-10' < fromDate AND '2010-12-27' > toDate) then
DATEDIFF(toDate, fromDate)
else 0
end as d9
FROM `lt_hperiods`
WHERE ('2010-12-10' BETWEEN Date(fromDate) AND Date(toDate) )
OR ('2010-12-27' BETWEEN Date(fromDate) AND Date(toDate))
OR ('2010-12-10' <= fromDate AND '2010-12-27' >= toDate)
AND (lt_id=1)) MQS