how to write sql query to count? [closed] - sql-server

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I want to write a query for count 'noOfDistribution' within a date
and by reference. for example, there are 2 in 1/5/2013.
In addition,can someone recommend some ebook/website to learn advanced skills in
query? Thanks for helping.

Answering your question:
SELECT input_Date, REFERENCE, count(*)
FROM YourTable
GROUP BY input_Date, REFERENCE
But it will result something different you pointed, since for the date 2/5/2013, it will count 6 elements for REFERENCE null

You can do something like thiss....
select count(Input_date) over (partition by Input_date,reference),* from table
By this you can find count of Particular date such as 1/5/2013 has 2 count
alternative way
select date,reference,count(*) from table group by date,reference

Related

I am getting multiple similar results from a like query, how can I combine results? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
The results of the below give me multiple values because of versions like
Bomgar v1.2
Bomgar v1.3
I would like them to combine into just one row.
select distinct ARPDisplayName0
from v_HS_INSTALLED_SOFTWARE
where ARPDisplayName0 like 'Bomgar%'
It looks like you want to put all Bomgar in the same bucket, but you still want all the other rows. So you need a CASE expression
select distinct
CASE WHEN ARPDisplayName0 like 'Bomgar%' THEN 'Bomgar' ELSE ARPDisplayName0 END ARPDisplayName0
from v_HS_INSTALLED_SOFTWARE;

SQL Statement two columns value return single value [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Please suggest best way to construct SQL statement thanks a lot!
example
Try this
select id,[date],(case when refund = 1 then 'R'
when voidstatus = 0 then 'C'
when voidstatus = 1 then 'V'
else '' end
) as [status],grossamt
from trans

Sort by dd from dd/mm/yyyy in SQL Server [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Get the records when entered value dd matches in dd/mm/yyyy instead of entering dd/mm/yyyy
Example if I entered only dd = 12 from dd/mm/yyyy.
Please can anyone help me?
this ?
WHERE DATEPART(DAY, datecolumn) = 12

Query that return city name and how many records exists in that city? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have created a project in C#. In my database I have a table "Users" in which there is a field "City". Now I want to put some query that returns all the cities and how many users belongs to that city. For example there are 9 users in that table and 3 users live in New York, 3 in Chicago and 3 in Washington so the output should be:
City- New York, Records- 3
etc.
Thanks.
Group by city and then get the count of cities.
select City, count(City) as Records
from Users
group by City

using min value in where query sql server [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a data in table like this :
==============================================================================================
id idPaper Code Sequential
==============================================================================================
1A506D10-9306-495A-9E4E-7081E3D3ACDB F4CFE90D-0921-4FB7-A236-5420B0892379 0036 2
3DB0FEBF-FBDF-4768-B36A-83AF4FB53E4B F4CFE90D-0921-4FB7-A236-5420B0892379 0035 1
I want display data like this :
==============================================================================================
id idPaper Code Sequential
==============================================================================================
3DB0FEBF-FBDF-4768-B36A-83AF4FB53E4B F4CFE90D-0921-4FB7-A236-5420B0892379 0035 1
1A506D10-9306-495A-9E4E-7081E3D3ACDB F4CFE90D-0921-4FB7-A236-5420B0892379 0036 2
I run my query:
select *
from tablename
where idPaper = 'F4CFE90D-0921-4FB7-A236-5420B0892379'
and min(sequential)
but it does not work. Please help me...
Thanks...
I think you just want to sort the data. Perhaps you just want:
select *
rom tablename
where idPaper='F4CFE90D-0921-4FB7-A236-5420B0892379'
order by sequential;
You can use order by.
select *
from tablename
where idPaper='F4CFE90D-0921-4FB7-A236-5420B0892379'
order by sequential

Resources