I am attempting to create a line graph in Report Builder using the following data:
TRWR rental 85805 2013-09-14 13:02:54.900
TRWR rental 74415 2013-09-15 18:00:00.420
VRWR rental 83017 2013-09-14 10:03:43.597
VRWR rental 73984 2013-09-15 18:00:01.203
HRWR rental 83017 2013-09-14 14:03:15.497
HRWR rental 74005 2013-09-15 18:00:01.957
And the query that I am using is the following:
select ServerName, DatabaseName, FileSizeMB, DISTINCT PollDate from DBinfo
where DatabaseName IN (#Database) AND ServerName IN(#Servers) AND PollDate Between #StartDate AND #EndDate AND PhysicalFileName LIKE ('%mdf')
However, when I attempt to create the chart the X axis (dates) are duplicating. This is how I've set it up. Can anyone please show me how I can enter distinct dates. Please see the link for the image: http://imgur.com/7nhP3B6
Well even though it is not the best method for determining duplicates it gets the job done generally. I would guess the first step in debugging your method is your dataset is actually returning duplicates. You can avoid this by merely stating:
Select DISTINCT ....
versus
Select .....
This is merely SQL syntax telling the database engine to list a distinct row for each result.
Related
I have a MS Access Table with the following information
DA Attendance
Attendance ID (Key)
Date
DA
Attendance Record (Dropdown with 6 options)
Note
I am trying to create a cross tab query that will display the following:
Query Result Example
I am able to get the crosstab query without any date parameters to work as intended. The picture above is how it looks. However, when I add the parameter I get the following error: "The expression is typed incorrectly, or is too complex to be evaluated..." . I have a form in which the user inputs a specific day for which to create the query.
Query Design 1
Query Design 2
Raw Data Example
Attendance ID
DA
Date
Attendance Record
Note
1
65
2021-09-16
Present
2
37
2021-09-16
No Call No Show
No text response
3
25
2021-09-16
Tardy
1155 AM arrival
4
58
2021-09-16
Present
PARAMETERS [Forms]![DA Attendance Form]![DA_Attendance_Date] DateTime;
TRANSFORM Count([DA Attendance].[Attendance ID]) AS [CountOfAttendance ID]
SELECT [DA Attendance].DA
FROM [DA Attendance]
WHERE ((([DA Attendance].Date)=[Forms]![DA Attendance Form]![DA_Attendance_Date]))
GROUP BY [DA Attendance].DA
PIVOT [DA Attendance].[Attendance Record];
Figured out the issue. MS Access is acting as the front end for a SQL Server database. The field "Date" was declared as type Date() in SQL Server which for whatever reason pulled as "Short Text" in Access. Edited the field type to DateTime() in SQL Server and it solved the issues when running the query.
I have the following schema in MySQL (read only permissions database)
http://sqlfiddle.com/#!9/1eafc/1
As you can see there are only 5 country codes:
GB, USA, GR, ES, DE
Some months some of the records might not contain one of the countries because no record was created for this country that month.
As you can see in the sqlfiddle, GB records were only created in September.
Is there any way if there isn't any record for a country in that month, instead of not being returned, to show 0 or NULL or something?
I've tried so far different variations of ISNULL, IFNULL and COALESCE but none of them worked.
I want to return something like the following
UK 0
USA 13
GR 5
ES 12
DE 1
Any ideas?
Ok, so in lieu of a functional SQLFiddle I will make a few assumptions. The country code exists in the same table as the grouped data.
If that is the case, why not use:
select DT1.CountryCode, count(DT2.ValueForCounting) as ReturnedCount
from (
select distinct CountryCode
from DataTable ) DT1
left join DataTable DT2
on DT1.CountryCode = DT2.CountryCode
and DT2.QueryConditions = 'Stuff' -- Use the join condition instead of a where clause for anything to do with DT2
your fiddle link not loading,
but i guess my two different ideas about that,
create function and manage it using if condition.
or
create view among month, country and mapping table and put month on left join
hope it works.
I have a grails application with a mysql database as the datasource. The mysql database is created and maintained by a third party. One of the tables 'visitinfo' contains 2 columns consisting of the 'userid' and 'logindatetime'.
userid is of type TEXT and logindatetime is of type 'datetime'.
In order to access the above table 'visitinfo', I have created a domain class 'VisitInfo' and mapped it to the mysql database table by which my grails application can easily store as well as retrieve data from the database.
On one of the pages, I am required to show visitor information for the last 30 days. So basically I am looking out for a solution to get number of visitors per day for the last 30 days. Something like this:
21-Jan-2012 ------ 36
22-Jan-2012 ------ 85
23-Jan-2012 ------ 115
24-Jan-2012 ------ 236
etc.
Also please note, that if a userid 'williamp' has 2 entries on a particular day, it should be counted as 2. So, am not looking out for uniqueness of users.
Any help will be appreciated.
I know nothing at all about grails. The MySQL query to obtain the desired result is as follows:
SELECT DATE_FORMAT(logindatetime,'%d-%m-%Y') dt
, COUNT(*) total
FROM visitinfo
GROUP
BY dt;
You want to use the countBy gorm method.
numLogins=VisitInfo.countByReleaseDateBetween(startOfDay,endOfDay)
This would need to be in a loop that calculates two date objects for each of the last 30 days. startOfDay would need a time value of 00:00:00:00 and endOfDay would need a time value of 23:59:00:00
I suggest following hql query to match your requirement
VisitInfo.executeQuery("select logindatetime, count(*) from VisitInfo group by logindatetime")
Evening folks,
I have a complex MySQL COUNT query I am trying to perform and am looking for the best way to do it.
In our system, we have References. Each Reference can have many (or no) Income Sources, each of which can be validated or not (status). We have a Reference table and an Income table - each row in the Income table points back to Reference with reference_id
On our 'Awaiting' page (the screen that shows each Income that is yet to be validated), we show it grouped by Reference. So you may, for example, see Mr John Smith has 3 Income Sources.
We want it to show something like "2 of 3 Validated" beside each row
My problem is writing the query that figures this out!
What I have been trying to do is this, using a combination of PHP and MySQL to bridge the gap where SQL (or my knowledge) falls short:
First, select a COUNT of the number of incomes associated with each reference:
SELECT `reference_id`, COUNT(status) AS status_count
FROM (`income`)
WHERE `income`.`status` = 0
GROUP BY `reference_id`
Next, having used PHP to generate a WHERE IN clause, proceed to COUNT the number of confirmed references from these:
SELECT `reference_id`, COUNT(status) AS status_count
FROM (`income`)
WHERE `reference_id` IN ('8469', '78969', '126613', ..... etc
AND status = 1
GROUP BY `reference_id`
However this doesn't work. It returns 0 rows.
Any way to achieve what I'm after?
Thanks!
In MySQL, you can SUM() on a boolean expression to get a count of the rows where that expression is true. You can do this because MySQL treats true as the integer 1 and false as the integer 0.
SELECT `reference_id`,
SUM(`status` = 1) AS `validated_count`,
COUNT(*) AS `total_count`
FROM `income`
GROUP BY `reference_id`
I have data stored as below in an MS Access database:
Date User
20090101 1001
20090101 1002
20090102 1001
20090103 1001
20090103 1003
I'm attempting to create a query which shows the daily running count of unique users. For example:
Date Daily Count Unique User Running Count
20090101 2 2
20090102 1 2
20090103 2 3
What's the best way to achieve this?
In most SQL implementations you could select using the aggregate function count(distinct user). But Access doesn't support that construct. I think the best you could do is to select the distinct values in a subquery and count them.
I was going to write a query but this link seems to do a good job.
HTH
Tom
Your query will look something like this...can't test it without the data though:
SELECT Date, Count(Date) As [Daily Count], Count(User) As [Unique User Running Count]
FROM TableName
GROUP BY Date
I did it! A simple solution is the best: no SQL coding needed.
In Access, Query Design,
Column 1 =
Field=Date
tablename=yourname
Total=Groupby
Column2 =
Field=Date
Table=yourname
Total=Count