I am trying to build a query that will build a output like this. The output that I go is this I was following the instructions here https://www.mysqltutorial.org/mysql-subquery/ My query is this What I was expecting to happen was the alias ‘patient appt’ to be populated with the data from the nested select statement. I was thinking this would work
Tag: count
Order count per ID and calculate time between orders in BigQuery
I am working with customer purchase data and am trying to write a query in Google BigQuery that sorts all purchases by date and adds a purchase/order count per customer (order_count). Also, I would like to calculate a time-delay (in days) between the orders of one customer (purchase_latency). My query currently looks like this: The result including “order_count” and “purchase_latency”
how to count all rows are approved in sql?
I have this line data, where it also shows the status: approved, in progress, not yet started. I need to count how many lines are ALL APROVED based on the line colors. the data is similar to this: the query should show that there is only color (which is green) that all the status are approved, because red still have
Calculate percentage using SQL
I am trying to find how I can calculate Percentage from table below From the above table, I am hoping to get the data with percentage like below. However my SQL statement below returns all percentage …
Retrieving specific column data from SQL sub-query
My goal is to pull out the values shown in red in the picture. I used this query to pull the data together. The rows are associated via ActionID and filtered with the ‘AND’ conditions shown. SELECT […
Sql assign unique key to groups having particular pattern
Hi I was trying to group data based on a particular pattern. I have a table with two column as below, I need to generate a key column that increment only after rollingsum equals 0 is encountered.As given below I am using postgres, I tried to increment variable in case statement as below But I am getting an error near
SQL – select where for specific id, all distinct values for other column exist
I am having a bit of a hard time explaining the logic I want to achieve in the title. Anyway, I have a database containing two tables (rent and car). The car table contains data about cars (license …
PostgreSQL, summing multiple date columns over multiple rows
Let’s assume the following table: CREATE TABLE assumption ( datetime_1 TIMESTAMP, datetime_2 TIMESTAMP, datetime_3 TIMESTAMP); Now I want to know the total amount of times a month is set in any row …
Date distinct count over week
Im trying to get a distinct count of user ids logs per day with every week as a partition for the distinct identification. e.g. if one user logs on Friday/Saturday of week 1, and on Monday/Friday of …
How to assign a field name to an SQL Count in AWS Athena SQL
I’m still new to Athena. I think I got my database defined correctly, as shown in Example 1 below. However, when I run a count query, I get results unlike what I would expect. Example 1: Works Fine except count is called “_col3” Result: Example 2: syntax error This query shows a syntax error when I click “Run Query”: Answer