Skip to content

Tag: sql

Using outer query ID in a subquery

I have a table with a list of invoices with there statuses and reported date, let’s say each date we have new report could change the invoice status from PENDING to PAID. I want subquery the first date an invoice was paid for each invoice. The table looks like this: invoice_id report_date status A1 08-2…

How to remove duplicates in CTE from VARIABLES and TEMPORARY TABLE

I was looking for this solution in internet and none of them worked properly. I decided to create variables, then accommodates it in the user defined function: It works properly, because for example I am able to return the top 10 Customer in the Furniture Category in 2011 and 2012 Then, I would like to have a…

Compering number to a current month in MS Access

I have a data table that looks like this: Id Month Number e1 9 2 e2 10 3 e3 10 1 e4 9 3 The month column is an integer. I want to get a sum of number both for October and September, but by using a reference to a current month and last month, as if the data is

MySQL remove zeros from decimal part if the number is whole

I have a sales table with price column as decimal(8, 2) and I’m running the query below to get the total price It’s working perfectly but my results are usually intergers so I end up with trailing zeros all the time. It’d be nice to just return the whole number if there is no decimal part An…

How to print pattern output in Oracle’s SQL

I have a table with below data Table : emp name A B C D Expected Output : names A AB ABC ABCD I only know how to print data in horizontal form Not sure how to cut the horizontal and get expected output Answer You can use a hierarchical query: Which, for the sample data: Outputs: NAMES A AB