只需更改一行,就可以在一个查询中添加更多选择

时间:2014-12-12 11:01:34

标签: mysql

我有这些选择

SELECT ah.IDA, ah.HFR1
FROM AHIS ah
WHERE                   
    ah.HFR1 > 0
    AND
  (ah.HFR1 >= $DATE_FROM AND ah.HFR1 < $DATE_TO)
  AND ( ah.TIME_MILIS < $DATE_TO)
    AND not exists (select 1
    from AHIS ah2
    where -(ah.HFR1) = ah2.HFR1 AND ah2.TIME_MILIS < $DATE_TO
   )
    AND
  ($FID = (SELECT a.IDFA FROM  `ITEM` a WHERE a.ID = ah.IDA LIMIT 1 ))
GROUP BY ah.IDA



SELECT ah.IDA, ah.HFR2
FROM AHIS ah
WHERE                   
    ah.HFR2 > 0
    AND
  (ah.HFR2 >= $DATE_FROM AND ah.HFR2 < $DATE_TO)
  AND ( ah.TIME_MILIS < $DATE_TO)
    AND not exists (select 1
    from AHIS ah2
    where -(ah.HFR2) = ah2.HFR2 AND ah2.TIME_MILIS < $DATE_TO
   )
    AND
  ($FID = (SELECT a.IDFA FROM  `ITEM` a WHERE a.ID = ah.IDA LIMIT 1 ))
GROUP BY ah.IDA

如您所见,HFR1,HFR2,HFR3等所有变化都是如此。 有什么方法可以把它放在一个查询中吗?

0 个答案:

没有答案