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
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.
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
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
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
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.
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] : 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
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
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
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