I am currently facing the following issue: I have 1 Table with my Broker Trading Data similar to this: The Goal is to say IF first OrderType (lowest Id where TradeId is the same) was a Buy, it’s a LONG Trade ELSE a Short Trade … output should be like this: What am I missing? How can I construct my
Tag: mysql
How to get common value based on a column from a table sql
I have a table. the screenshot is given bellow: There have two columns item_details_id pay_method_id In item_details_id there have 1,2,1 data. On the other hand pay_method_id have 1,1,3 data. I want to get only common values of pay_method_id depending on item_details_id. According to the given screenshot- in …
What is the correct way to use LEFT JOINS, GROUP BY, and ORDER BY together?
I have an SQL Query (MySQL) which uses a combination of LEFT JOIN, GROUP BUY, ORDER BY, and LIMIT. When I remove LEFT JOIN and GROUP BY it works fine. What is the correct way to add in my additional LEFT JOIN and GROUP logic to make this work? Answer Your syntax is incorrect – where clause will be befor…
MySQL GROUP BY slows down query x1000 times
I’m struggling with setting up proper, effective index for my Django application which uses MySQL database. The problem is about article table which for now has a little more than 1 million rows and querying isn’t as fast as we want. Article table structure looks more or less like below: After man…
how i get my 2nd id in the join table in mysql
SELECT package.pkg_name, pkg.cat_id,pkg.id FROM pkg INNER JOIN package ON pkg.id=package.id join categories ON pkg.cat_id=1=categories.cat_id=1 1st id is show in join table but 2nd id does not show …
Mysql IF statement Error on Nested if sentence
I am trying to create a procedure to update the stopTime field on my works table. The query I am using is: update mydb.works set stopTime= (IF((SELECT table_name FROM information_schema.tables …
Display the data that does not exist in particular table using multiple interconnecting table join
I am trying to list all students that did not enroll in this subject yet using the var_subjectcode as filter. I am using the code below but it is not working properly. It keeps on resulting empty …
How to filter rows that has multiple condition MySQL
I have a table that contains my product details Now I want to write a query that gives me product_id(s) with this conditions: Brand = Intel model = Core i7 I’ve tried this one but it didn’t returns any rows, I guess I should use JOIN. Answer Use group by and having: Or better yet, using tuple equa…
SQL query to find the concurrent sessions based on start and end time
Below is a sample dataset showing TV sessions of each TV set of each household. Household “111” switch on their TV “1” at 500 and switch it off at 570. However, this has been captured in the data as 2 separate rows. You will have to write a query to convert this into a single row. Similar modification needs t…
Sort MySQL query with multiple joined tables
My query uses left join to fetch multiple values from the table objects_values. I’m having trouble sorting the results the way I want; if ASC, then show the objects with the lowest attribute values first, and if DESC, show the objects with the highest attribute values first. I have actually managed to g…