visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Databases :: MySql :: MySql column count


By: FiatLink Belgium  Date: 02/11/2004 09:06:21  English  Points: 20 Status: Answered
Quality : Excellent
I have 1 table 'cities' with 2 columns 'name1, name2'.
Have ---> Would like
'name1' 'name2'
Amsterdam Utrecht Amsterdam 2
Amsterdam Leusden Den Haag 1
Leusden Den Haag Leusden 2
Utrecht 1

I prefer one query which has the result presented as above.
By: VGR Date: 04/11/2004 20:30:26 English  Type : Answer
You may try those three queries :

CREATE TEMPORARY TABLE tmp
SELECT name1 AS name, COUNT(*) AS nbr
FROM cities
GROUP BY name1;

INSERT INTO tmp
SELECT name2 AS name, COUNT(*) AS nbr
FROM cities
GROUP BY name2;

SELECT * FROM tmp;

NB : your table layout is not adapted at all to the queries you wanna run ;-)

Do register to be able to answer

EContact
browser fav
page generated in 231.575970 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page