Skip to content
Advertisement

Tag: subquery

How to do an arithmetic operation with aliased column in SQL

I have a databse table as like below: Here, received_by and sent_by are two user ID those who are receiving and sending the product respectively. I want to calculate the total amount of each product of a single user by subtracting the sent amount from received amount. My current query looks like below: Here I get an error that Unknown

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

Two conditions based on subquery. How to shorten it?

I have working query basing on 2 subqueries. I would like to know what to do to do not have to paste 2 times my big sql query and just use this two conditions in one line? Is this possible? Answer I am guessing that you really want: Unlike your query, this guarantees that the two columns are on the

Advertisement