Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

help about sql

imba23

Professional
Advanced Member
Messages
165
Reaction score
0
Points
26
mga sir ganto po yung table ng sql ko

id candidate position partylist
---|---------|---------------|--------|
1 | Bryan | President | LEAP |
2 | Miko | Vice President| SHARE |
5 | Nico | Vice President| LEAP |
3 | Miko | Vice President| SHARE |
4 | Bryan | President | LEAP |
6 | Miko | Vice President| SHARE |
7 | Bryan | President | LEAP |
7 | Joe | President | SHARE |

tapos dapat ganto po yung result na makuha ko

candidate Position partylist Votes
--------|---------------|--------|-------|
Bryan | President | LEAP | 3 |
Miko | Vice President| SHARE | 3 |


ano pong query dyan mga sir?

thank you po!


P.s. meron din po akong tanong sa stackoverflow, mas maayos po yung pag kaedit ng table dun haha
eto po yung link: Click Me
 
Last edited:
mga sir ganto po yung table ng sql ko

id candidate position partylist
---|---------|---------------|--------|
1 | Bryan | President | LEAP |
2 | Miko | Vice President| SHARE |
5 | Nico | Vice President| LEAP |
3 | Miko | Vice President| SHARE |
4 | Bryan | President | LEAP |
6 | Miko | Vice President| SHARE |
7 | Bryan | President | LEAP |
7 | Joe | President | SHARE |

tapos dapat ganto po yung result na makuha ko

candidate Position partylist Votes
--------|---------------|--------|-------|
Bryan | President | LEAP | 3 |
Miko | Vice President| SHARE | 3 |


ano pong query dyan mga sir?

thank you po!


P.s. meron din po akong tanong sa stackoverflow, mas maayos po yung pag kaedit ng table dun haha
eto po yung link: Click Me

*** Bakit nga pala dalawa yung id 7?

*** Pakilinaw yung result na gusto mo. Base sa pagkaka-intindi ko, ang gusto mo lumabas ay yung top 1 for those 2 positions, tama ba? Kailangan ba kasama pa sa display yung mga "winners" for each positions? Or gusto mo naka-list down lang lahat based on the number of votes.

For now, ito na muna ang paunang query until mai-detailye mo ang buong result na gusto mo.
Ang result nito ay: nasa pinakaitaas ang may pinakamadaming votes, regardless kung ano ang position.
Code:
select candidate, position, partylist, count(id) as Votes
from <table>
group by candidate, position, partylist
order by count(id) desc
 
SELECT candidate, position, partylist, count(id) AS Votes
FROM table_name
GROUP BY candidate;
 
*** Bakit nga pala dalawa yung id 7?

*** Pakilinaw yung result na gusto mo. Base sa pagkaka-intindi ko, ang gusto mo lumabas ay yung top 1 for those 2 positions, tama ba? Kailangan ba kasama pa sa display yung mga "winners" for each positions? Or gusto mo naka-list down lang lahat based on the number of votes.

For now, ito na muna ang paunang query until mai-detailye mo ang buong result na gusto mo.
Ang result nito ay: nasa pinakaitaas ang may pinakamadaming votes, regardless kung ano ang position.
Code:
select candidate, position, partylist, count(id) as Votes
from <table>
group by candidate, position, partylist
order by count(id) desc
typo lang po yung double id na 7 sorry xD

okay na po solved na po sir thank you po!
 
Last edited:
mga sir ganto po yung table ng sql ko

id candidate position partylist
---|---------|---------------|--------|
1 | Bryan | President | LEAP |
2 | Miko | Vice President| SHARE |
5 | Nico | Vice President| LEAP |
3 | Miko | Vice President| SHARE |
4 | Bryan | President | LEAP |
6 | Miko | Vice President| SHARE |
7 | Bryan | President | LEAP |
7 | Joe | President | SHARE |

tapos dapat ganto po yung result na makuha ko

candidate Position partylist Votes
--------|---------------|--------|-------|
Bryan | President | LEAP | 3 |
Miko | Vice President| SHARE | 3 |


ano pong query dyan mga sir?

thank you po!


P.s. meron din po akong tanong sa stackoverflow, mas maayos po yung pag kaedit ng table dun haha
eto po yung link: Click Me

sir aral ka po basic rdbms or database relationship much better po yan keysa bigan ka nang sagot tapos hindi morin maiintindihan bakit naging ganyan try mo po aral niyan from scratch madali mo nalang malaman si table relationship left/right/inner/out joins
 
Back
Top Bottom