473,396 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with Query SELECT COUNT

263 100+
Hi.

I have a table in a mysql db:

[HTML]
NAME ROLE DATE TYPE

MARK STR 2008-04-28 B
KARL MAN 2008-04-28 A
KARL IRE 2008-04-28 A
JIM IRE 2008-04-28 A
PATTY MAN 2008-04-28 C
PATTY STR 2008-04-28 C
[/HTML]


On this table execute this query:

Expand|Select|Wrap|Line Numbers
  1. SELECT
  2. COUNT(TYPE) AS tot
  3. FROM tbl_1 
  4. WHERE DATE BETWEEN '2008-04-28' AND '2008-04-28' 
  5. GROUP BY TYPE, DATE
  6. ORDER BY DATE
The result is:

NR 1 row for TYPE = B
NR 3 row for TYPE = A
NR 2 rows for TYPE = C

As you can see the column NAME actually contains 4 names divided by ROLE.

I want the query counts once the name:

NR 1 row per TYPE = B ( NAME = MARK )
NR 1 row per TYPE = A ( NAME = KARL )
NR 1 row per TYPE = A ( NAME = JIM )
NR 1 row per TYPE = C ( NAME = PATTY )

Then 4 rows finals, instead of 6 extracts now with the query, which also counts double names.

It's possible ?
Thanks x your attention
Viki
Apr 29 '08 #1
1 1577
rpnew
188 100+
Hi,
I came up with something like this if it helps...
Expand|Select|Wrap|Line Numbers
  1.  select distinct name, count(type) as tot from table1 where date between '2008-04-28' and '2008-04-28' group by role,name order by date;
  2.  
Regards,
RP
May 5 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Nicolas Payre | last post by:
Hi, I have the following SQL that I want to use to update a table. It doesn't work ! Does someone knows why? ** I Know it could be done easy with a CURSOR FOR LOOP, but still... Thanks for...
0
by: krystoffff | last post by:
For the following query, I have a little problem ... First, I have to rewrite several times the same query because the alias are not recognised in the same query ( I got an error when I try to...
3
by: Ian T | last post by:
Hi, I've got what I think (probably incorrectly) should be a simple SELECT : Two colums with data like col1 col2 1 50 1 51 2 50
4
by: dwight0 | last post by:
I am having a problem with a query, I am not sure if i would use a join or a subquery to complete this problem. I have two queries, and i need to divide one by the other, but i cant seem to get...
3
by: Robert | last post by:
Greetings I have been trying to write a script that will list out the size of each user table in a specified DB. I am running into a scoping problem when trying to format my display. I am sure...
15
by: Hemant Shah | last post by:
Folks, We have an SQL statement that was coded in an application many years ago (starting with DB V2 I think). When I upgraded to UDB 8.2, the optimizer does not use optimal path to access the...
20
by: Development - multi.art.studio | last post by:
Hello everyone, i just upgraded my old postgres-database from version 7.1 to 7.4.2. i dumped out my 7.1 database (with pg_dump from 7.1) as an sql-file with copy-commands and to one file using...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
29
by: wizofaus | last post by:
I previously posted about a problem where it seemed that changing the case of the word "BY" in a SELECT query was causing it to run much much faster. Now I've hit the same thing again, where...
58
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.