I have the following table named PRICES: VERTEXID TIMEID PRICE 6001 20191231 104.3 6001 20181231 115.3 6001 20171231 138.3 6001 20161231 122.3 6002 20191231 102.3 6002 20190931 123.3 6002 …
Tag: subquery
SQL script within subquery (Big Query)?
Is there a way to have SQL scripts within a subquery ? For example: In my case it is not possible to move the variable declaration outside of the subquery. Thanks ! Answer For this particular example, you could use a CTE to define the parameter values:
Subquery – define select list. The subquery returns the same value for each result line
do you know what I have done wrong? My subquery is returining the same value for all lines. Thanks a lot in advance for your any advice! 🙂 Answer I think you just want conditional aggregation:
Postgresql – access/use joined subquery result in another joined subquery
I have a database with tables for equipment we service (table e, field e_id) contracts on the equipment (table c, fields c_id, e_id, c_start, c_end) maintenance we have performed in the past (table m,…
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
Group query in subquery to get column value as column name
The data i’ve in my database: I ran a query to group by id and status to get the below result: I want to use the above query as subquery to get the result below, where the distinct status are column name. Any other approach to get the final data is also appreciated. Let me know if need more info.
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
How do I use OR in mySQL on a Select statement with a greater-than condition?
So I am basically building this mySQL sports database and have a table in which there is a ‘Home_Team’ and ‘Away_Team’, as well as ‘Home_Score’ and ‘Away_Score’. What I need is a query which displays the winning team and score. So it has to select one team if the score is greater than the other team’s; and vice-versa. I have
SQL – ordering table by information from multiple tables
Title of the question may not have been very clear – I am not really sure how to name this question, but I hope that my explanation will make my problem clearer. I have 3 tables: [1] score id rating_type 1 UPVOTE 2 UPVOTE 3 DOWNVOTE 4 UPVOTE 5 DOWNVOTE 6 DOWNVOTE [2] post_score post_id score_id 1 1 1 2