|
Supposing we have the following records in an SQL Server table.
Date 19/5/2009 12:00:00 pm 19/5/2009 12:15:22 pm 20/5/2009 11:38:00 am
What is the SQL syntax for getting something like this one?
Date Count
19/5/2009 2
20/5/2009 1
Started by strakastroukas on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Select convert(....
VARCHAR(10), YourDateColumn, 101), COUNT(*) FROM YourTable GROUP BY CONVERT(VARCHAR(10, YourDateColumn), DATEPART(mm, YourDateColumn), DATEPART(dd, YourDateColumn), COUNT(*) FROM YourTable GROUP the date type to do this.
|
|
I've been tasked with writing a script to do some file processing, and I need to be able to do a simple query against a SQL server to verify the counts on the server match up to how many the database thinks there should be.
Since I've never done much ...
Started by Zypher on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at serverfault):
Yes, you can query MSSQL DB.
There's a whole ORA book on exactly this topic.
Look up DBI and DBD.
|
|
I need help in indexing in MySQL. I have a table in MySQL with following rows:
ID Store_ID Feature_ID Order_ID Viewed_Date Deal_ID IsTrial
The ID is auto generated. Store_ID goes from 1 - 8. Feature_ID from 1 - let's say 100. Viewed Date is Date and time...
Started by Tesnep on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
All of why you're doing COUNT(viewed_date) instead of COUNT(*) ? Is viewed_date ever NULL? If not, you can just use the COUNT....
And will be able to grab the COUNT from the cardinality summary of the index if the table is MyISAM.
|
Ask your Facebook Friends
|
Hello together,
Our Company has serveral SQL Server Enviornments, some of them work with MS-SQL Server 2005 Express Edition others with Standard or Enterprise Edition.
In a discussion today a DBA said MSSQL Express Ed. would be less performant then the...
Started by Johannes on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at serverfault):
The total total for a DB can be larger than this as transaction log files do not count.
Then 4Gb in size.
|
|
I'm trying to do some basic paging in MSSQL. The problem I'm having is that I'm sorting the paging on a row that (potentially) has similar values, and the ORDER BY clause is returning "random" results, which doesn't work well.
So for example.
If I have...
Started by footose on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
ROW_NUMBER() OVER....
Ordering by [RowIndex] ASC should sort it out.
Possibly not what you intended.
Try ordering by both, e.g.: ORDER BY Rating DESC, DateEdit ASC
The query first numbers the rows by [Rating], and then re-sorts the results by [DateEdit] .
|
|
When I use a calculation or a subquery in my ORDER clause which is already in my SELECT clause, does SQL know to just order by that column? Or does it recalculate everything for each row when sorting?
For instance, lets say I'm writing a terrible query...
Started by Jarrett on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
SELECT EmployeeName, (SELECT COUNT(*) FROM Employee e2 WHERE MgrID = Employee.EmployeeID) FROM Employee ORDER BY (SELECT COUNT(*) FROM Employee e2 WHERE MgrID = Employee.EmployeeID)
could also be expressed like
SELECT EmployeeName, (SELECT....
|
|
Hi folks,
I use the following stored procedure from my MS SQL Server 2008 database to return a value to my C#-Program
ALTER PROCEDURE [dbo].[getArticleBelongsToCatsCount] @id int AS BEGIN SET NOCOUNT ON; DECLARE @result int; set @result = (SELECT COUNT...
Answer Snippets (Read the full thread at stackoverflow):
I think it should be like this:
ALTER PROCEDURE [dbo].[getArticleBelongsToCatsCount] @id int, @NumberOfRows int OUTPUT ... .
It looks like you are returning the status of the Count query execution when you really want the value of COUNT (*) .
|
|
Ho together,
a report in my application runs a query that needs between 5 - 15 seconds (constrained to count of rows that will be returned). The query has 8 joins to nearly all main-tables of my application (Customers, sales, units etc).
A little tool...
Started by Kovu on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
For instance, I just ran this query on a large... .
Like, a debit without a credit and these kinds of stuff .
Your query may returns portions of data as of before UPDATE and portions as of after UPDATE in a single query .
NOLOCK means placing no locks at all.
|
|
I'm working with php and I want to do a next button that's step to the next 10 records (like when you browse question with stackoverflow) I don't know how to do that but I'm thinking to do it with Top n record ? Do you think that's a good idea ? Any suggestion...
Started by Bigballs on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Doesn't mssql have something like LIMIT in mysql? so you could do:
select xxx from yyy this be any help to you?
$count=$_POST[page]*10;
for MySQL:
$rowsPerPage = 10; $offset = ((int.
Equivalent is.
|
|
I have 3 tables - Items, Props, Items_To_Props
i need to retun all items that match all properties that i send example
items 1 2 3 4 props T1 T2 T3 items_to_props 1 T1 1 T2 1 T3 2 T1 3 T1
when i send T1,T2 i need to get only item 1
Tnx. Eyal
Started by eyalb on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
FROM (SELECT itemId, count(distinct prop) propCount FROM items_to_props WHERE prop in ('T1', 'T2') GROUP T.itemId FROM (SELECT i.itemId, count(distinct p.prop) propCount FROM items_to_props i JOIN #P p on i.prop = p.prop GROUP BY i.itemId....
|