Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
SELECT *
FROM RF_CustomerCard
WHERE DateOfBirth IN (
SELECT DateOfBirth
FROM RF_CustomerCard
HAVING COUNT(DateOfBirth) > 1
GROUP BY DateOfBirth
)
SQL Server 2019 is saying I have a syntax error by "GROUP"
I am trying to find employees who have the same date of birth
As D. Use a GROUP BY clause with a HAVING clause from Microsofts's SELECT - GROUP BY- Transact-SQL shows HAVING comes after GROUP BY:
SELECT *
FROM RF_CustomerCard
WHERE DateOfBirth IN (
SELECT DateOfBirth
FROM RF_CustomerCard
GROUP BY DateOfBirth
HAVING COUNT(DateOfBirth) > 1
)
ORDER BY DateOfBirth -- Optional
Related
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 4 months ago.
Improve this question
on which day most people login?
Use DAYNAME() like that.
SELECT DAYNAME([column_with_date])
FROM [table]
GROUP BY DAYNAME([column_with_date])
order by count(DAYNAME([column_with_date])) desc limit 1;
You can use below code to find max frequency
select date,max(freq)
from (SELECT date,count(date) as freq from TableName
group by date);
this will give the Date and max frequency of that date in column.
or you can use below code
SELECT date,count(date) as freq from TableName
group by date
limit 1;
here i'm assuming date as column name.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 months ago.
Improve this question
select sum(orderinfo.orderamount) as total, userinfo.username
from orderinfo
left join userinfo on orderinfo.userid = userinfo.userid
group by orderinfo.userid
order by total desc
Table orderinfo:
userid
orderamount
Table userinfo:
userid
username
I will need to search for top 10 most buy users with their names.
But I got this error:
Msg 8120, Level 16, State 1, Line 1
Column 'userinfo.username' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
I am using SSMS. I must be doing something wrong...please help
Thanks
You cannot aggregate by the userid and also select the username. The quickest fix here would be to aggregate by both the userid and username:
SELECT SUM(oi.orderamount) AS total, ui.username
FROM orderinfo oi
LEFT JOIN userinfo ui ON oi.userid = ui.userid
GROUP BY ui.userid, ui.username
ORDER BY total DESC;
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I received 1052 error code. How can I add an alias to this code below?
SELECT consumerid as , count(stars) as starcount
FROM consumer left JOIN review on consumer.consumerid = review.consumerid
group by consumerid
ORDER by reviewcount asc, consumerid asc;
consumer_id is ambiguous in the query since it belongs to both tables. You need to qualify it with the identifier of the table it belongs to. It is generally a good practice in SQL to qualify all columns in multi-table queries.
select c.consumerid, count(r.stars) as review_count
from consumer c
left join review r on c.consumerid = r.consumerid
group by c.consumerid
order by review_count, c.consumerid;
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
What's the simplest SQL statement that will return the duplicate values for a given column for example ORDERS_NUMBERS and group it by oldest CREATION_DATE in an Oracle database table?
SELECT ORDER_NUMBERS, count(*)
FROM YourTableName
GROUP_BY ORDER_NUMBERS
HAVING count(*) > 1
ORDER BY CREATION_DATE
select ORDERS_NUMBERS,CREATION_DATE,count(*)
from
table
group by ORDERS_NUMBERS,CREATION_DATE
order by CREATION_DATE desc
having count(*) > 1
select
t.orders_numbers,
t.creation_date
from table t
group by t.orders_numbers,
t.creation_date
having (count (*) >1)
;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
how to get top 1,00,000 customers name and email id who have booked maximum number of tickets? The table has columns like:
NAME, CUST_ID, JOINING DATE, NO. OF TICKETS BOOKED, EMAIL_ID.
Something like the following should work if you are using Microsoft Sql server (tsql)
Select TOP 120 columns FROM table ORDER BY columns desc
SELECT TOP 100000 NAME, CUST_ID, [JOINING DATE], [NO. OF TICKETS BOOKED], EMAIL_ID
FROM YOUR_TABLE
ORDER BY [NO. OF TICKETS BOOKED] DESC
Are you looking for this ?
if you are working with SQL SERVER