Skip to content

Tag: sql

SQL statement to count occurrences in list

i would like to run an SQL query to calculate the number of passes and fails in a list. I’ve created a scenario with students and grades to better explain my problem. I have 2 tables one being the student table studentid firstname lastname 1 Sponge Bob 2 Patrick Star and another table being the grades s…

Add join and search in columns for any string

I have these Postgres tables: I use this SQL query: How I extend this SQL query to search also in table employees by employee id and filter the result by any character found in table columns first_name and last_name? Answer You can join the new table using employee_id:

Show All Duplicate Records QUERY

What is the query that will show all the records that have multiple names? For example. Table 1: Desired result: Answer You can use GROUP BY and join result to origin table

LIMIT and OFFSET returning repeating results

There seems to be a bug in my query that causes results to repeat when I increment the OFFSET value. It is supposed to show 20 results per page. Only 3 results match what my query is looking for, but for some reason, some of these results repeat themselves even though they should only appear on the first page…

Calculating win streak from list of fixtures

I have a table fixtures with a list of matches played between two players in each, identified by their ID. I’m trying to use the table to calculate rolling winning/losing streaks for each player, but I’ve been having issues with my query below (see more on SQL Fiddle): Below is the desired result,…

Return only ALL CAPS strings in BigQuery

Pretty simple question, specific to BigQuery. I’m sure there’s a command I’m missing. I’m used to using “collate” in another query which doesn’t work here. Desired return: JOHN@EMAIL.COM,STACY@EMAIL.COM Answer Consider below If applied to sample data in your question …