------解决方案-------------------- select sum(case when WAY=1 then OUTNUM else null end) WayOut1, sum(case when WAY=1 then INNUM else null end) WayIn2, sum(case when WAY=2 then OUTNUM else null end) WayOut3 from USER WHERE TIMEID>123
------解决方案-------------------- 用Group By就行了吧?
Select timeid, way, SUM(outnum), SUM(INNUM) From user Group By timeid, way