April 17, 2013 at 3:34 am
Hi,
I want to use group by on one column which is having many entries
table_a
Name price
AAA 12
BBB 13
AAA 0
CCC 24
AAA 0
DDD 0
Now I want to find out `Name` which is having `Price` as `0`
but as I'm having entries `AAA` 3 times I can't directly write simple sql with condition
`NOT Equal to 0`
Please help me I want to print result for above table_a should be
only `D` as it is having `0` as `price`.
April 17, 2013 at 3:44 am
ashuthinks (4/17/2013)
Hi,I want to use group by on one column which is having many entries
table_a
Name price
AAA 12
BBB 13
AAA 0
CCC 24
AAA 0
DDD 0
Now I want to find out `Name` which is having `Price` as `0`
but as I'm having entries `AAA` 3 times I can't directly write simple sql with condition
`NOT Equal to 0`
Please help me I want to print result for above table_a should be
only `D` as it is having `0` as `price`.
SELECT 1 FROM table_a a WHERE NOT EXISTS (SELECT 1 FROM table_a b WHERE b.name = a.name AND b.Price > 0)
For better assistance in answering your questions, please read this[/url].
Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]
April 17, 2013 at 3:49 am
I have done by using having clause
SELECT name,SUM(price) as price
FROM table
GROUP BY name
HAVING SUM(price) = 0
Thanks 🙂
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply