Skip to content

Ordering data, Paginator on django

The program I’m making is to display information about a product from the database. The program works fine, the problem is that I want to order by last name and not the “owner”. For example. …

Filtering with OR vs IN

A common filter in SQL procs goes something like: WHERE (@a = 0 OR @a = a) Obviously the idea being to filter on a if a positive parameter was provided to the proc, but to otherwise show all results. …

JOIN on two tables

I have two tables: user: and credential: I want to perform a query to get the following result (one row for every user): Right now I am executing this query: This results in: I want a single row for a user. How can I achieve this? Answer You can use two joins:

Count from multiple columns and rows simultaneously in SQL

I have a table of matches which look like: I need to find the total matches played by every team and the output should be like this: I know about SUM() and GROUP BY clauses but not able to do it on multiple columns. Any help would be highly appreciated. Answer You can use union all to unpivot the data

Group data in intervals

I need to group data in intervals of 15 (or X) minutes in sql. For example, i have the next scenario. The result that i expect to obtain is I tried using Lag function but i dont get what i want, because it add interval to each row and continues grouping. Thanks in advance and apologies for my bad english.

Populate all rows of a column with same value

The issue is that I have a PostgreSQL table ‘currency’ with 4 columns: ‘id’, ‘symbol’, ‘name’, ‘quote_asset’. The table contains 225 rows and column ‘quote_asset’ has all the values set to ‘null’ for now (it wasn’t popul…