c++ - Trouble in showing SUM() value of a column -
hello fellow colleagues stackoverflow!
i brief, , cut point:
i work on windows xp, in c++, using ado access ms access 2007 database.
i have table in ms access 2007 contains 2 columns of interest titled typeofobject , instaledpower.
the actual table looks this:
| typeofobject | instaledpower | ------------------------------- | type1 | 1000 | ------------------------------- | type2 | 2000 | ------------------------------- | type3 | 450 | ------------------------------- | type4 | 800 | ------------------------------- | type1 | 800 | -------------------------------
i need query displays typeofobject , sum( instaledpower ) type, in manner:
if value of typeofobject type1 or type2, show it's value in table unchanged, else mark othertypes. result should this:
| typeofobject | sum(instaledpower) | ------------------------------------- | type1 | 1800 | <--- 1000 + 800 = 1800 ------------------------------------- | type2 | 2000 | <--- 1 type2, 2000 ------------------------------------- | othertypes | 1250 | <--- sum( instaledpower ) of type3 , type4 ------------------------------------
i have tried query:
select typeofobject , sum( instaledpower ) [sum(instaledpower)] mytable group typeofobject ;
but this:
| typeofobject | sum(instaledpower) | ------------------------------------- | type1 | 1800 | <--- correct ------------------------------------- | type2 | 2000 | ------------------------------------- | type3 | 450 | <-- ------------------------------------- |-- isn't need, see above | type4 | 800 | <-- -------------------------------------
i have tried browsing through archive, , found similar things, nothing me.
by searching through internet, have come conclusion problem might solved pivot tables, not know how use them properly.if case, if pivot table can solve this, links appreciated.
if there else can help, ask , gladly it.
thanks tries help.
select iif(typeofobject in('type1', 'type2'), typeofobject, 'othertypes') typeofobject , sum( instaledpower ) [sum(instaledpower)] mytable group iif(typeofobject in('type1', 'type2'), typeofobject, 'othertypes')
;
i not sure if syntax works in access 2007, databases prefer case
expression instead of iif()
.
it important, however, repeat first expression in select list in group by.
Comments
Post a Comment