• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: SQL query to count number of accounts based on criteria A only, B only and both A&B

Resolved: SQL query to count number of accounts based on criteria A only, B only and both A&B

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

Basically, I have a table that tells about type of communication to accounts(either by letter or email) like :
ACOUNT_ID TYPE_OF_COMM
1 Letter
1 Letter
3 EMail
2 Letter
4 EMail
4 Letter

and so on.. A query needs to be written that counts :
  1. the number of accounts that received letter only,
  2. the number of accounts that received mails only,
  3. the number of accounts that received both letters and mails

So the output of above should be :
Type_of_comms Count of Accounts
Letters only 2
EMail only 1
both letters and mails 1

Thanks in advance!

Answer:

I’m not familiar with Athena, but as long as it supports CTEs / subqueries, this should work:

If you have better answer, please add a comment about this, thank you!

athena sql
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: When converting markdown to latex with pandoc, how can I end a block before the next heading?

26/03/2023

Resolved: TYPO3 SQL error: Field ‘tx_imagezoom_set’ doesn’t have a default value

26/03/2023

Resolved: std::regex_replace to replace multiple combinations

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.