| Author |
Topic |
|
RaxSuur
Starting Member
7 Posts |
Posted - 2005-08-19 : 02:09:18
|
| Hai. I'm very bad at sql, but I'm making a little project here.I need to do query from a table:Table: Col A--Col B--Col C12-----6------012-----2------144012-----4------012-----7------139013-----3------254013-----5------320013-----4------013-----5------425014-----8------250014-----9------242014-----8------014-----2------0 And query should be like this: Col A--SumOf Col B--Col C12-----19-----------144012-----19-----------1390Can somebody help me please? 13-----17-----------254013-----17-----------320013-----17-----------425014-----27-----------250014-----27-----------2420 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-19 : 02:18:47
|
| Try thisSelect G.ColA,G.sumB, ColC from yourTable T inner join (Select colA, sum(ColB) as sumB from yourTable group by ColA) G on T.colA=G.colA and T.ColC<>0MadhivananFailing to plan is Planning to fail |
 |
|
|
RaxSuur
Starting Member
7 Posts |
Posted - 2005-08-19 : 02:37:49
|
| Sorry, my text is on the table. I'll post it againTable: Col A--Col B--Col C12-----6------012-----2------144012-----4------012-----7------139013-----3------254013-----5------320013-----4------013-----5------425014-----8------250014-----9------242014-----8------014-----2------0And query should be like this: Col A--SumOf Col B--Col C12-----19-----------144012-----19-----------139013-----17-----------254013-----17-----------320013-----17-----------425014-----27-----------250014-----27-----------2420Important is not to SUM Col C, I must see all rows where Col C > 0Thanks to Madhivanan, but this is not exactly what I need. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-19 : 02:42:25
|
| WellI edited my posts and it seems you didnot see thatI post my edited query hereSelect G.ColA,G.sumB, ColC from yourTable T inner join (Select colA, sum(ColB) as sumB from yourTable group by ColA) G on T.colA=G.colA and T.ColC<>0MadhivananFailing to plan is Planning to fail |
 |
|
|
RaxSuur
Starting Member
7 Posts |
Posted - 2005-08-19 : 03:09:12
|
Well, perhaps your SQL statement is right, but I'm working in Access and it says that JOIN expression not supported. Thank You for help. I must figure out something else. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-19 : 04:17:21
|
| WellThis should work in AccessSelect G.ColA,G.sumB, ColC from yourTable T inner join (Select colA, sum(ColB) as sumB from yourTable group by ColA) G on T.colA=G.colA where T.ColC<>0MadhivananFailing to plan is Planning to fail |
 |
|
|
RaxSuur
Starting Member
7 Posts |
Posted - 2005-08-19 : 04:41:30
|
| OK. It also works without JOIN. I got it from another forum:select a.colA, b.colX, a.colCfrom t1 a, (select colA,sum(colB) colX from t1 group by colA) bwhere a.colA = b.colA and a.colC <> 0 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-19 : 04:51:09
|
| YesIt is derived table concept which does the same functionalityMadhivananFailing to plan is Planning to fail |
 |
|
|
mmarovic
Aged Yak Warrior
518 Posts |
Posted - 2005-08-19 : 05:52:21
|
| Two queries are equivalent, second one just uses the old join syntax that should be avoided. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-19 : 05:58:50
|
quote: Originally posted by mmarovic Two queries are equivalent, second one just uses the old join syntax that should be avoided.
mmarovic, will not that old join supported in newer versions?MadhivananFailing to plan is Planning to fail |
 |
|
|
mmarovic
Aged Yak Warrior
518 Posts |
Posted - 2005-08-19 : 06:13:10
|
| I don't know, but I hope it will be dropped, the sooner the better. |
 |
|
|
|