I was reading this post from StackOverFlow to adjust query to calculate stock from 3 tables. I have 3 tables tblItems, tblPurchase and tblSales. tblItems contains items information like below. Screenshots of my tables tblItems: tblPurchase: tblSales: And my expected result like below In query result items det…
Tag: sql
Update table with using NEWID() function
In general, I would update a table randomly like the following scripts. However, I get some issue. It would update more/less then 2 rows. I try execute the following scripts many times for debug. The results are not always only two records. If I remove the order by newid(), the number of output result will be…
How do I find the 4th record in SQL/ SAS PROC SQL?
Initially I tried including a sample SAS Table here but I can’t get the script to line break where it should – Appreciate if you can let me know how to manually insert the line break when typing in the text editor, thanks My question: For SAS PROC SQL – How can I return the 4th highest recor…
Finding Similar People’s Names from Database
I have a table in MySql with names in it. I am trying to, given an input name, find all similar names in the table. I’ve heard a lot about Levenshtien/Damerau–Levenshtein distance, but it doesn’t seem like it would work well for this, I’ll explain my reasoning later. To elaborate: User input…
Is it possible to change a WordPress/woocommerce title that is written with uppercase to appear capitalized?
I am currently working on a project that is based on WordPress and as an e-commerce platform, it uses WooCommerce. I made a product migration from an old site that has the product titles written in uppercase. Currently I have this html code for the titles inside a product: So I want the product title to appea…
SQL SELECT query to get stock qty does not return value in function ( but does from phpMyAdmin)
I am running this code in a function in WordPress/Woocommerce to update stock values to the wp_stock_log table when I manually edit stock levels. I am attempting to get the most recent ‘qty’ value for the product and then set it as var $old_qty. I then want to insert it into the table in a new row…
Get First Record of Each Group
First I would like to apologize if it is a basic question. So, i have monitoring data being stored every 5 seconds. I want create a query that returns me the first record every 10 minutes, for example:…
TSQL – Compare two columns with self join – Calculate the difference between yesterdays total’s and today’s total
I’m trying to calculate the difference between today’s and yesterday’s totals on a column. If a self join isn’t the best way to do that, that is fine, whichever will give me the result I’m after …
Find SQL table rows where there are multiple different values
I want to be able to filter out groups where the values aren’t the same. When doing the query: SELECT category.id as category_id, object.id as object_id, object.value as value FROM …
SQL group and summing at new row
I have an issue where I am trying to create a new “row” (not part of the database) where it only gives me the SUM of the “count” column. I am wondering if that is possible? I tried adding the SUM(count(cost) as “total product cost” OVER() AS Total_Count; but that just creat…