I want to filter on a case statement in my where clause for example: Select name, address, case when code in (50000-8113, 512388-8114) then ‘M345’ else ‘N/A’ end as Mucode Where mucode = ‘…
Tag: sql
MERGE Statement is not working in Informix v10
I tried to use the merge statement to Insert/Update in Informix v10.0 but it throws a Syntax Error: Could you please help? Answer The MERGE statement was not available in Informix 10.00. It was added in 11.50 — see the MERGE statement in the SQL syntax manual. The new features page suggests it was added in 11.50.xC6, part of the
Understand the logical query processing when ‘Between’ condition is used in a self join of a SQL query
I have the following Orders table in PostgreSQL Database I need to return the cumulative sum of revenue for every order_date from last 2 days including the revenue for that order date. I am using the following query and it returns following result As per logical order of the query processing following steps will be performed The ‘JOIN’ will first
DB2 : SQL: Change in granularity for SCD type-2 table
I have a order table in SCD type-2 like below (Delivery Date in Order granularity and it create history when when delivery date changes) Order_Id Order_Status Order_Create_Dt Delivery_Dt Start_Date …
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 many tries I came that below index gives best
Multiple select statements in single query while using ‘group by’ and ‘join’
I have three tables – podcasts, videos and others. Each of the entities under these are associated with a category and subcategories. Example for podcasts – This category_id and subcategory_id have their name values in their respective tables – Now, I want to get the count of podcasts, videos and text under each category & subcategory combination. My individual SQL
Eloquent hasMany doesn’t load collection
I’m relatively new to eloquent, and have problems loading data from a hasMany relation in an app that uses eloquent as the database layer. My (simplified) code is as follows: The SQL Schema is like below I then do the following query: This results in a json like the following Raw SQL query shows me that I do have data
Arabic text in sp_sqlexec insert return question mark
Records are imported into table #FileRecords and ##TableInsert are dynamic tables, it can be table A, table B(which justify the reason of using exec sp_sqlexec). When Arabic wording going through sp_sqlexec, it will insert ??? instead of the Arabic wording. Is there anything I am not aware of, beside of encoding and N in front of the string? Output: Above
Use multiple but identical aggregate function
I’m trying to use two identical aggregate function is SQL Server, where I use COUNT(A) with some condition and COUNT(A) with another condition. For example I want to count all students enrolled in the course ABC, and the second count I want to count all students who have grade A and have enrolled in the same course ABC. But the
Microsoft SMSS – Joining tables on t2.primary key = t1.foreign_key
I need to join two tables together to create a table with columns for employee id, employee name and their boss’ name. The ‘hier’ table The ’employees’ table The query I wrote is almost working, putting an employee name in the right spot, but not the right employee: Which outputs: I need to have each person’s boss to have the