Page 1 of 1

merging datas idea?

PostPosted: Wed Feb 25, 2015 12:21 pm
by yanzco
i was stuck on this..

i have a table..
queried results like

apple 1
banana 2
mango 1
apple 5
cherry 2
peanut 2
mango 2
and so on.. etc..

i wanted to show the merged results in a box or text like this
apple 6
banana 2
mango 3
cherry 2
peanut 2

any ideas how i can do that?

Re: merging datas idea?

PostPosted: Wed Feb 25, 2015 3:09 pm
by stu
Try this:

Syntax: [ Download ] [ Hide ]
Using SQL Syntax Highlighting
SELECT fruit, SUM(amount) AS Total FROM t1 GROUP BY fruit
Parsed in 0.010 seconds, using GeSHi 1.0.8.10

Re: merging datas idea?

PostPosted: Wed Feb 25, 2015 6:04 pm
by yanzco
hmmm.. i kinda tried it.. not sure.. but

the table is displayed as a record of the food eaten on that day..
so it could be a long list..

i need that long list to be displayed...
and at the same time..

i want to display at least something like this when the user clicks on the table..

lets say, ont the list.. i clicked apple..
the text beside the table shows.. apple : 6
or if i click banana on the table.. it would show.. banana 2

doing the above without changing the queried table
apple 1
banana 2
mango 1
apple 5
cherry 2
peanut 2
mango 2
and so on.. etc..

:o

Re: merging datas idea?

PostPosted: Wed Feb 25, 2015 11:03 pm
by Gaev
yanzco:

1) What is the "database id" ?

2) What is the "table" ?

3)
the table is displayed as a record of the food eaten on that day..

What is the "filter" you use in your dbpQuery command for this ?

lets say, ont the list.. i clicked apple..
the text beside the table shows.. apple : 6
or if i click banana on the table.. it would show.. banana 2

a) you can expand the SQL command from stu with a "WHERE clause" that filters the records the same way as you would in dbpQuery.

b) in order to get the "sum of just the selected fruit" ... you would expand the "WHERE clause" further to include just the "selected fruit name" ... and you can get the "selected fruit name" using the special NeoBook variable [yourID.yourTableName.yourFruitField].

Re: merging datas idea?

PostPosted: Thu Feb 26, 2015 5:55 am
by stu
Here's pretty much the same query using a WHERE clause so you can have only results for this year, in this case about Computer Equipment, using only 3 fields of the table.

Image

Maybe you should create a view instead of using the contents of your original table. But yeah, I didn't quite get your second post, if you can elaborate a bit more that would be great.