Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I am try to understant how to make a table that tells me in which specific day were written the most mentions about the persons in my table.
SELECT
person,
COUNT(1) AS count_mentions,
COUNT(DISTINCT current_date) AS mention_per_date,
FROM
`aesthetic-honor-311413.big_data_alon_peled_2021.israel_media_person`
GROUP BY
person
ORDER BY
current_date asc
LIMIT
10;
EXPECTED RESULT:
person mention_per_date
Tomer 24
Shalev 18
Yosef 15
Eran 15
Gal 11
(Fictive names and numbers)
I am try to understant how to make a table that tells me in which specific day were written the most mentions about the persons in my table.
For this question, I would expect a query like this:
SELECT person, date, COUNT(*)
FROM `aesthetic-honor-311413.big_data_alon_peled_2021.israel_media_person`
GROUP BY person, date
QUALIFY ROW_NUMBER() OVER (PARTITION BY person ORDER BY COUNT(*) DESC) = 1;
This returns the date that most frequently occurs for each person. You don't mention the name of the date column, so this just uses date.
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 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
I am having a problem to write a select to a following table:
user_id
email
user_name
task_id
status
date
123
123#email.ru
user_user
456
approve (or decline)
2021-03-3121:11:10.367485
I need to make a select for dates 1.03 to 31.03 for each user (name, email and id) to show how many tasks he did in total, how may of them were approved and how many were declined.
1.You should show the table structure first by
\d table_name。I need know the type of date
2.I guess the type date is timestamp.
3.total_count he done:
select count(1) from table_name where user_id=1231 and date between '2021-03-01' and '2021-04-01';
4.group by status
select count(1),status from table_name where user_id=123 and date between '2021-03-01' and '2021-04-01' group by status
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 2 years ago.
Improve this question
I have a hospital data set where each patient is admitted with a diagnosis.
I want to display each patient once with the diagnosis each patient is admitted with with most times.
right now each patient that have multiple diagnoses appear in multiple rows.
the dataset is similar to this
$ Subject_id diagnosis
1112 SEIZURE
1112 GASTROINTESTINAL BLEED
1112 SEIZURE
1113 FEVER
how do I collapse and display the multiple diagnosis to one row and show by the most frequently used diagnosis?
You can use window functions and aggregation:
select sd.*
from (select subject_id, diagnosis, count(*) as cnt,
row_number() over (partition by subject_id order by count(*) desc) as seqnum
from t
group by subject_d, diagnosis
) sd
where seqnum = 1;
Note: If there are ties for the most common diagnosis, this arbitrarily returns one row. If you want all rows in the event of ties, then use rank() instead of row_number().
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 years ago.
Improve this question
I have 2 columns, one is showing the email and the other one shows the date the email was created.
What I'm trying to do is something like this:
registered customer 4 Date 01-01-2018
registered customer 2 Date 01-02-2018
registered customer 9 Date 01-03-2018
Any help would be appreciated.
Thanks
If table stucture consist of 2 columns(email, created_at) you should groupping your data by created_at field.
Example:
select date, count(email) as count
from your_table
group by date
You appears to want :
select date, count(email) as emailcount
from table t
group by date;
EDIT : Use count() instead of sum() & if you want to count day wise email as registered customer then use the date in GROUP BY clause instead of doing aggregation.
SELECT SITEID, THEDATE, COUNT(EMAIL)
FROM [database].[dbo].[table]
WHERE LOGIN NOT LIKE '' AND SITEID = 'someSiteId' AND
THEDATE >= '2017-01-01'
GROUP BY SITEID, THEDATE
ORDER BY THEDATE ASC;
Depending on how many entries you have, you could also do:
Select Num, date
FROM table
ORDER BY date
Then make Num be an identity column in the table that matches the email with a customer number. Maybe not as ideal depending on your data...but if you are referring to the customer by their number you may potentially want that info in the table.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a student table where column is name, attendance, and date in which data is entered everyday for the students who attend the class. For example if a student is absent on a day, entry is not made for that particular student for that day.
Finally. I need to find out students name whose attendance less than 50.
You can use GROUP BY and HAVING statements for this.
SELECT name FROM student GROUP BY name HAVING COUNT(*) < 50;
Please note that above query is not tested.
You have to use GROUP BY clause to aggregate similar student in table and HAVING check your condition, to get your desired output.
SELECT name, count(name)
FROM student
GROUP BY column_name
HAVING count(name)<50;
I hope this will help to solved your problem.
SELECT name
FROM StudentsTable
WHERE COUNT(name) < 50