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
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 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.
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 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 a id which is having more than one Accountid in a table with status Active . I need to find group of active for the particular ID .
Please find my below query .is it correct or something need to modify to get better optimized result .
select id,count(Accountid) from CustomerAccount
where status='Active'
group by id
having count(*)>( select min(maxxount) from(
select id,count(accountid) as maxxount
from CustomerAccount
group by id)A)
Use this query:
select id,count(Accountid) from CustomerAccount
where status='Active'
group by id
having count(*) >1
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 9 years ago.
Improve this question
cust_id acct_id trxn_amt trxn_cnt
1 66685638 10,028,717,398 199.75 5
2 66685638 10,028,849,377 76.16 2
Say I have a table of customers with multiple account IDs and I want to create a new column for that's the summation of all of the transaction amounts for each customer (199.75+76.16 for cust_id=66685638) as well as another column thats the % of total spend for each account (for first account its 199.75/(76.15+199.75)). Each customer may have anywhere from 2-4 acct_ids.
Thanks so much.
what about:
select cust_id,
sum(trxn_amt) as total_amount,
trxn_amt / sum(trxn_amt) as pct
from customers
group by cust_id
order by cust_id;
or if you want to see each individual row from the customers table:
select cust_id,
acct_id,
trxn_amt,
sum(trxn_amt) as over (partition by cust_id) as total_amount,
trxn_amt / sum(trxn_amt) as over (partition by cust_id) as pct
from customers
order by cust_id;