这句SQL语句能简化吗??? ( 积分: 50 )

  • 主题发起人 主题发起人 Jason Law
  • 开始时间 开始时间
J

Jason Law

Unregistered / Unconfirmed
GUEST, unregistred user!
select&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fItem='a')&nbsp;as&nbsp;SWSR,&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fItem='b')&nbsp;as&nbsp;SPSR,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fItem='c')&nbsp;as&nbsp;DKSR,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fItem='d')&nbsp;as&nbsp;PJSR,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fItem='e')&nbsp;as&nbsp;LJSR,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fItem='f')&nbsp;as&nbsp;QTSR,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fFlag=1)&nbsp;as&nbsp;ZSR,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fItem='g')&nbsp;as&nbsp;SDF,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fItem='h')&nbsp;as&nbsp;ZGGZ,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fItem='i')&nbsp;as&nbsp;FZ,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fItem='j')&nbsp;as&nbsp;SS,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fItem='k')&nbsp;as&nbsp;GQWL,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fItem='l')&nbsp;as&nbsp;SPJH,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fItem='m')&nbsp;as&nbsp;DKJH,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fItem='n')&nbsp;as&nbsp;GGFY,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fItem='o')&nbsp;as&nbsp;XZFY,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fItem='p')&nbsp;as&nbsp;RCKZ,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fItem='q')&nbsp;as&nbsp;PJHC,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fItem='r')&nbsp;as&nbsp;QTKZ,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fFlag=0)&nbsp;as&nbsp;ZKZ,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fFlag=1)&nbsp;-&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(select&nbsp;sum(fMoney)&nbsp;from&nbsp;tIncomeAndExpenses&nbsp;where&nbsp;fFlag=0))&nbsp;as&nbsp;LR
 
有点晕...&nbsp;针对fItem用Group&nbsp;By,然后在内存里完成&nbsp;'a'&nbsp;-&gt;&nbsp;SWSR之类的转换吧...<br>ps:&nbsp;可以在内存中&nbsp;Create一个ClientDataSet然后向其中写数据的...
 
用group&nbsp;by&nbsp;然后再行列转换吧。
 
后退
顶部