I am creating my first mobile application using HTML5 and JqueryMobile. Storing all datas in localstorage. Anyone can suggest me the easy way to retrieve grouped data count from following resultset,
1 mango
2 orange
3 mango
4 apple
5 mango
6 apple
7 orange
8 orange
9 apple
10 mango
Expected result
mango 4
orange 3
apple 3
you can do the same using query lik
SELECT Fruit_Name, COUNT(*) as "Fruit Count"
FROM Fruits
GROUP BY Fruit_Name;
Selecting data and rendering in HTML5 is explained here.
Related
Extending this question for a more general case:
I have a table called fruits with a column fruit that has three possible values: apple, orange, and mango. I used the following query to get the counts of each fruit by date:
SELECT date, fruit, COUNT(id) AS count
FROM fruits
WHERE date BETWEEN '2020-10-02' AND '2020-10-05'
GROUP BY date, fruit
that gives the following results:
date fruit count
--------------------------------
2020-10-02 apple 3
2020-10-02 orange 5
2020-10-03 orange 23
2020-10-03 mango 1
2020-10-04 mango 9
2020-10-05 apple 10
2020-10-05 orange 7
2020-10-05 mango 6
As you can see, not every date contains each type of fruit.
Is it possible, and if so, how, to add the missing fruit by each date to the above results with a default count=0, as shown below?
date fruit count
--------------------------------
2020-10-02 apple 3
2020-10-02 orange 5
2020-10-02 mango 0
2020-10-03 orange 23
2020-10-03 mango 1
2020-10-03 apple 0
2020-10-04 mango 9
2020-10-04 apple 0
2020-10-04 orange 0
2020-10-05 apple 10
2020-10-05 orange 7
2020-10-05 mango 6
Use a cross join ot generate the row and then a left join to bring in the results:
select d.date, f.fruit, coalesce(ff.count, 0) as count
from (select distinct date from fruits) d cross join
(select distinct fruit from fruits) f left join
fruits ff
on ff.date = d.date and ff.fruit = f.fruit;
I am a newbie still learning jsp and mysql.
I have a database with following table fields:
id no letter content
1 1 book
2 2 pen
3 3 a apple
4 3 b mango
5 3 c banana
6 4 car
I need somebody help me, how can I do a query in jsp with mysql so the result will be like this?
No Content
1. book
2. pen
3. a apple
b mango
c banana
4. car
I have to design a Google Form wherein users can provide multiple responses to a particular question. The number of responses can vary from user to user and does not have a fixed upper limit (Would mostly never go above 20 but still can't put a number on it). For example:
Response 1
Name: John
Age: 26
Answer: Apple
Banana
Response 2
Name: Mike
Age: 28
Answer: Guava
Mango
Orange
Now, this is how I want this data to look in the spreadsheet:
Name Age Answer
John 26 Apple
John 26 Banana
Mike 28 Guava
Mike 28 Mango
Mike 28 Orange
How to achieve this? Any help will be appreciated.
I have many users that can select their choice from rank 1-4.
The table look like this:
username rank1 rank2 rank3 rank4
Perter Apple Orange Grape Melon
Adam Orange Melon Apple Grape
James Melon Grape Orange Apple
How do I get a table like this in php mysql
username Apple Orange Grape Melon
Peter 1st-choice 2nd-choice 3rd-choice 4th-choice
Adam 3rd-choice 1st-choice 4th-choice 2nd-choice
Jame 4th-choice 3rd-choice 2nd-choice 1st-choice
I have two tables and they have "Many to Many" relation. The problem is in mirror table where I have 2 more fields "name" and "status". For name field values will be "Youtube, DailyMotion and Mp4Upload" and for status values will be "Subbed, Dubbed and Raw". For every link I am placing these value and the duplication occurs.
Demo:
mirror table
id name link status
1 Mp4Upload Some link 1 Subbed
2 Mp4Upload Some link 2 Subbed
3 Mp4Upload Some link 3 Subbed
4 Mp4Upload Some link 4 Raw
5 Mp4Upload Some link 5 Raw
6 YouTube Some link 6 Dubbed
7 YouTube Some link 7 Dubbed
Is there any way I can avoid repeated content by some relation? Like consider the above relation. One episode have many mirrors and many mirrors belong to one episode. We solved this using a third table pivot table episode_mirror.
Other Tables are
episode table
id name
1 First Episode
2 Second Episode
3 Third Episode
4 Fourth Episode
episode_mirror (pivot table)
id episode_id mirror_id
1 1 1
2 1 2
3 1 3
I hope this make sense to every one and thanks a lot.
Create a table for both name and status.
status_id | status
1 | subbed
2 | dubbed
3 | raw
name_id | name
1 | mp4upload
2 | youtube
3 | dailymotion
Then in your first table, use ids corresponding to those new tables
id name_id link status_id
1 1 Some link 1 1
2 1 Some link 2 1
3 1 Some link 3 1
4 1 Some link 4 3
5 1 Some link 5 3
6 2 Some link 6 2
7 2 Some link 7 2
This will save you a large amount of space and repetition from repeating the strings.