Any SQL experts here?
#1
Scooby Regular
Thread Starter
Join Date: Sep 2001
Location: A powerslide near you
Posts: 10,261
Likes: 0
Received 0 Likes
on
0 Posts
Any SQL experts here?
Have some tables with multiple columns and want to count the values in each column.
e.g. columns in table are a1, a2, ....a99.
All column hold different types of data.
So, for example, I would expect results as follows:
col, val, count
a1, 89, 232
a1, 23, 9876
a1, 1221, 23
a2, 'Bob', 234
a2, 'Fred', 4322
a3, 'The times', 543
a3, 'Telegraph', 22231
etc......
e.g. columns in table are a1, a2, ....a99.
All column hold different types of data.
So, for example, I would expect results as follows:
col, val, count
a1, 89, 232
a1, 23, 9876
a1, 1221, 23
a2, 'Bob', 234
a2, 'Fred', 4322
a3, 'The times', 543
a3, 'Telegraph', 22231
etc......
#4
Scooby Regular
Join Date: Apr 2004
Location: Tynemouth
Posts: 213
Likes: 0
Received 0 Likes
on
0 Posts
select count(col) as c, col from table group by col;
and repeat for each column you want to do this on. could do some stuff with pivots and systables if you wanted to automate it!
and repeat for each column you want to do this on. could do some stuff with pivots and systables if you wanted to automate it!
Last edited by AlexJReid; 02 April 2008 at 02:21 PM.
#6
Scooby Regular
Join Date: Sep 1999
Location: Bedfordshire
Posts: 4,037
Likes: 0
Received 0 Likes
on
0 Posts
If you need to count all columns then you need to include all columns in the select statement, long-winded yes unless you write a stored proc which will build the sql for you and use expression evaluation to run the dynamic sql. Bottom line is its very poorly modelled (which may or may not be something you can change).
#7
Scooby Regular
Thread Starter
Join Date: Sep 2001
Location: A powerslide near you
Posts: 10,261
Likes: 0
Received 0 Likes
on
0 Posts
Exactly, just how a client datbase storing it's data :banghead:
on mysql - which hasn't impressed me tbh coming from a sqlserver/oracle/db2 background!
on mysql - which hasn't impressed me tbh coming from a sqlserver/oracle/db2 background!
Thread
Thread Starter
Forum
Replies
Last Post
The Joshua Tree
Computer & Technology Related
18
11 September 2015 09:24 PM
Mkhan
Non Scooby Related
14
09 August 2001 02:07 AM