473,320 Members | 1,991 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,320 software developers and data experts.

Getting Count(*) when using pseudo pivot tables...

In the usual case, this SQL

select count(*) from mytable where ...

returns an accurate count of the rows you want.

But how do I go about counting rows from this SQL (the sum...if
statements function as a pseudo pivot query)?
SELECT sum(IF(date_report = ('2005-06-30'),shares,0)) as 'Q2
2005',sum(IF(date_report = '2005-03-31',shares,0)) as 'Q1 2005' from
companies left join positions on co_id = positions_co_id where
positions_co_issue_id = 7194 AND date_report
in('2005-06-30','2005-03-31') group by co_id order by 'Q2 2005' DESC
In this case, I'll end up with a row count of, say, 360. When I try to
count the rows I come up with numbers way different. For instance, this try:

select count(co_id) from companies left join positions on co_id =
positions_co_id where positions_co_issue_id = 7194 AND date_report
in('2005-06-30','2005-03-31')

....might give me 1000, while this one...

select count( distinct co_id) from companies left join positions on
co_id = positions_co_id where positions_co_issue_id = 7194 AND
date_report in('2005-06-30','2005-03-31')

....might give me 320.

I'd sure appreciate any thoughts!

--Brent
Oct 23 '05 #1
0 1371

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Clive Moss | last post by:
I am in the middle of writing a system for a client who has Access 2000 installed on 8 PC's I have Access 2002 and the system I have written relies on pivot tables to display results. I now find...
4
by: Del | last post by:
I need to create Pivot table in Excel from Access. Currently I run a query and output the data to an excel worksheet and create the pivots via automation. The issue I face is that the query may...
2
by: Joe | last post by:
Hi All, I am new to using the Access DB and I need some help if someone is able to give it to me. What I want to do is get the names of the columns of certain tables. Not the data in the table...
0
by: Dave | last post by:
I am trying to develop Data Access Pages (DAP) within Access 2003, specifically using Pivot Table Lists. When creating pivot tables as forms, all of my records in a table consisting of over 18,000...
2
by: cefrancke | last post by:
I can't seem to find a straight answer for my specific issue. Any help would be appreciated. I would like to count the various items in a table where the fields have a 'group' relationship. I...
3
by: George Sakkis | last post by:
After a brief search, I didn't find any python package related to OLAP and pivot tables. Did I miss anything ? To be more precise, I'm not so interested in a full-blown OLAP server with an RDBMS...
4
by: dallasfreeman | last post by:
I'm looking at a quick way to get results that are displayed as rows to display as columns. I have three tables:- - The Questions for the survey - The Results of the survey (Columns are listed...
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="...
3
by: Thyag | last post by:
Hi All, I need to group multiple tables in to a pivot. Could some body help me. Thanks in Advance, Thyag
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.