I’m trying to join 2 tables and count the number of entries for unique variables in one of the columns. In this case I’m trying to join 2 tables – patients and trials (patients has a FK to trials) and count the number of patients that show up in each trial. This is the code i have so far: The
Tag: count
SQL how to create a view with 2 sums of diferent tables, when those tables have diferent number of rows
I have 3 tables, “accounts” “charges” and “payments” I want to create a view with the account data the sum of the charges, and the sum of the payments, but payments have usually more records than charges for the same account when I create the view and GROUP BY charges end up “duplicated” like by the number of rows mismatch.
SQL want efficient query to SELECT columnA, columnB FROM table1 WHERE both columnA, columnB are in columnC FROM table2 WHERE columndD > value
I’m searching for a more efficient method to accomplish something that I’ve already solved with a few different SQL statements. The problem: I have two tables a transactions table, and an accounts table The transactions table has columns that look like: acct_sending acct_receiving amount tx_datetime 100 101 10 yyyy-mm-dd hh-mm-ss 101 100 5 yyyy-mm-dd hh-mm-ss 101 200 1 yyyy-mm-dd hh-mm-ss
SQL count() not showing values of 0
i just started my journey with SQL, and made some tables of Cyclists, and Cycling Teams. Cyclist’s table contains columns: ID, Name, Team (which is foreign key of TEAMS ID) Team’s table contains columns: ID, Name, Number of Cyclists I want to Count number of Cyclists in each team, by using count() function ( Or basically any function, i just
Count and Group by 2 different columns SQL
I have below table and want to find out a count and group by that will show the number of times republic of ireland played a particular opponent regardless if they are the home team or away team I want something that will show like the below Thanks for help! Answer This is how I would do it — normalize
Can I get two count results in a query?
I am using MariaDB. I want to have two count results in a query. The first query is: Next is: What I want to get is: How can I combine them? Answer The usual way is to make a Case..When statement that is one or zero for the desired condition and then SUM it, not COUNT it.
How can eliminate the line that counts everything [COUNT function in SQL]
I was running a code where I needed to see the top 10 results in a table. Unfortunately, I am with one more row that I was expecting. My results was the following: [Result after the query][1] [1]: https://i.stack.imgur.com/KCu7W.png Is there any way I can eliminate row 1 from my query? Thank you in advance for any assistance! Answer try
Simplifying SQL query
I’m using the Bixi public dataset found at https://www.bixi.com/en/open-data and have been asked to find “the average number of trips a day for each year-month combination in the dataset”. Here’s an example of the table from which I’m querying: id start_date start_station_code end_date end_station_code duration_sec is_member 85843 2016-04-15 00:00:00 6315 2016-04-15 00:05:00 6315 349 1 85844 2016-04-15 17:16:00 6315 2016-04-15
GROUP on one column and aggregate counts based on distinct values in another column
I have a table with values like so: I want to do a GROUP BY based on ts and display the counts for distinct values of usr_id like below. ts count of A count of B count of others 11 2 1 3 22 0 1 0 33 1 0 3 http://www.sqlfiddle.com/#!9/bbf4fc/2 I couldn’t make much progress beyond doing the
Count users with a condition in MYSQL
I have a table ‘helpdesk’ (detail below) that lists tickets. I’m trying to get the top 10 users who report issues, however there is a complication in the fact that users can report an issue for another user (think secretary for their boss as an example). The table structure is… Using the example above the count should return User 1