Skip to content

How to use count(‘condition’) over(partition by xx) in SQL

Here is the database: The first table is named Trip and the second table is Users. CLIENT_ID and DRIVER_ID are foreign keys for USERS_ID in the Users table. I want to find how many orders cancelled by the non-banned driver and non-banned passenger for each day (Trip.Status != ‘completed’ and Users…

SQL ARITHMETIC OPERATION

I am trying to get the sum of two rows using (+) operator in select. But when one column is null, the column for the SUM will also be null. If 2019 have sales amount of 20,000 and 2020 with 0 or null, the TOTAL_SALES will also be NULL I am wondering if there is a way to make the

Aggregate yearly data based on different months using SQL

I have a table ‘Amounts’ where I have the monthly payments of customers. Every customer has a row for each payment he has made. I want to aggregate their payments yearly starting from the month they paid first. For example in the table given below, for userID 132, I want to aggregate his payments …

SQL Subselect calculated in one row

I have a trouble getting an SQL select to work. I have one table – below is the example: I want to calculate the sum of every entry under 10 hits and every entry over 10 hits in one output. Like below: I tried inner join and outer join but I think that’s the wrong approach. If I do a

MariaDB native UTC time on update

I’m searching for a value that changes the value of a column to the current UTC time when the row is updated, but UTC_TIMESTAMP and GETUTCDATE only works as default value, not when used in ON UPDATE. …