I am trying to query an oracle database and get a list of names in a single cell of the result. I have a query like the following which produces the names in separate rows: SELECT (lastname || ‘, ‘ |…
MySQL query to get last 12 months data grouped by month including zero counts
I have table orders (order_id, order_processed_date). I want the count of orders per month for last 12 months. If any month has 0 orders, then it should print 0. Something like this: Total Orders | …
How to pass a php variable in WHERE clause of SELECT statement?
I have a php variable that I want to fetch another field in database using this variable in my where clause. My code: But this is printing me nothing. Don’t know where I am going wrong but any help would be appreciated. Answer You can either break the string and concatenate the variable with “..&#…
knex postgres join as nested JSON
I’m using knex with postgresql db, I have a row in table A which has one-to-one relation to rows in table B and one-to-many relation to rows in table C. I wanna join a row from A with B and C and get a json like Where stuff like aCol means column from table A, bCol – column from table
How to insert NULL into the DATETIME coulmn instead 1900-01-01 00:00:00.000 in SQL Server
I am new to SQL Server here I am trying to insert date into the column which has DATETIME as datatype . When I pass a datetime to the stored procedure from API it insert the values which I have …
Running total in Access Query based on item and date
I’m struggling with an Access Query trying to create a calculated field which presents a running total of parts that have gone or returned in the store; sorted in the order of date in one table. The table “DMPartsT” would look like below: The result I am aiming for is for the query to return…
WordPress delete posts not in specific categories using wpdb query
How do I modify the following query to delete all posts with the custom post type “listings” that are NOT IN specific WordPress categories? Note, I must use $wpdb->query() in my particular situation. My categories for exclusion are term ID’s 21, 22, and 24. UPDATE – THIS query bring…
Oracle SQL query to get Weekly Records
I have oracle database table ‘my_table’ with few sample rows as following- Case_ID Start_Date End_Date STATUS 123 01/10/2018 03/10/2018 Close 124 02/10/2018 Open 125 03/…
SQL: Give the names of employees who earn more than their manager
Hi guys, I have this type of table, and I need to show the employees who earn more than there managers? It would be easier if we had 2 tables, but I cannot imagine a code within one table. Any ideas? Answer You can do “self-join” between the two tables. In the second table, EMPNO will be equal to …
Exclude weekends and public holiday for SQL datediff
this code works but seems like the results are off by 1 day Objective: Find the datediff for the two dates given. However, we will have to exclude Weekends Public Holiday Example The difference …