|
amandarobe
Starting Member
2 Posts |
Posted - 01/28/2013 : 15:30:44
|
I have the following SQL statement and I need to order by fp.group_id. When I try to use the order clause at the end as I have it below, I get an error saying: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
My eyes are starting to cross, so I'm hoping someone can tell me where to place the order by clause so that the data is sorted by fp.group_id. I have tried several options and none seem to work.
select distinct lh.lid,ROUND(cast(lh.value as numeric),1),fc.minor_stage,fc.moderate_stage,fc.major_stage,(select fp.group_id from fpinfo fp where lh.lid=fp.lid order by fp.group_id), (select MAX(validtime) from fcstheight where basistime>'2013-01-25 20:00:00' and fcstheight.lid=lh.lid and ts='FF' and value=(select MAX(value) from fcstheight fta where fta.lid=lh.lid and fta.basistime=(select MAX(basistime) from fcstheight where fta.lid=fcstheight.lid))),(select MAX(value) from fcstheight fta where fta.lid=lh.lid and fta.basistime=(select MAX(basistime) from fcstheight where fta.lid=fcstheight.lid) and fta.basistime>'2013-01-25 20:00:00') from fpinfo fp, latestobsvalue lh,fcstheight ft,floodcat fc where lh.lid=ft.lid and fc.lid=lh.lid and lh.pe='HG' and lh.obstime>'2013-01-25 20:00:00' and lh.value>(select (minor_stage-1) from floodcat fc where fc.lid=lh.lid) and lh.value>(select MAX(fta.value) from fcstheight fta where fta.lid=lh.lid and fta.basistime=(select MAX(basistime) from fcstheight where fta.lid=fcstheight.lid)) group by fp.group_id,lh.lid,ROUND,fc.minor_stage,fc.moderate_stage,fc.major_stage order by fp.group_id; |
|