August 6, 2007 at 8:19 am
Hello,
I have a table with the following data: store, articles
I need to know how many articles in each store, in one sql query.
I know we can write smthg like:
select count(articles) from mystores group by store
But then i can't manipulate the data i get in my query! I am not writing t-sql, just a query.
I need to know for a given store the number or articles concerned.
Is there a way with CASE for example? Smthg like:
SELECT store, count(articles) ,
CASE store
WHEN '1' THEN store1count = store1count + 1
WHEN '2' THEN store2count = store2count + 1
ELSE 0
END
"total" FROM mystores
how can i define store1count and store2count in my query... remember , i can't use t-sql...
tx for helping!
August 6, 2007 at 8:26 am
Use Sum(Case when x=y then 1 else 0 End) as xxx
Cheers,CrispinI can't die, there are too many people who still have to meet me!It's not a bug, SQL just misunderstood me!
August 6, 2007 at 9:15 am
August 6, 2007 at 9:15 am
this could be good, but it will give me results under the following format:
st1count st2count st3count
article1 10 0 0
article2 0 20 0
article3 0 0 30
while i need smthg like:
count
article1 10
article2 20
article3 30
I don't know if this is possible, actually in my case each store sells one kind of article....
August 6, 2007 at 9:19 am
August 6, 2007 at 9:20 am
August 6, 2007 at 9:44 am
Actually, I think i complicated the question
I would like a count of the articles, grouped by article, no matter the store... but if i do a simple select count, i will get the results like:
article1 10
article2 20
article3 30
but how can i use the result i get if i don't assign each count result into a variable name?
Here's a code example (with some js), where i execute my query for one type of article only.
<query schema="articles" operation="select">
<select>
<node expr="count(@article)"/>
</select>
<where>
<condition expr= {"article = 'article1' "} />
</where>
</query>
);
var resultSet1 = myQuery.ExecuteQuery();
logInfo ("nb of articles1:" + resultSet1.somethinghere);
Right now, i am writing this code for as mnay articles as I have.
I am not able to do it dynamically.
I hope i was clear this time.
In all cases thanks again!
August 6, 2007 at 10:06 am
August 6, 2007 at 10:11 am
it's a rich client application
August 6, 2007 at 10:15 am
August 6, 2007 at 10:20 am
mmmm not sure... it's a pre-written application, and I can't change much in the core code.
Can you give an example of what it would be?
tx!
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply