Skip to content
Advertisement

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-26-2021 PAID A2 08-26-2021 PENDING A3

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 all records (2011-2014) in

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 Answer like akina said

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

SELECT list expression references column xxx which is neither grouped nor aggregated at, why need to use subquery?

So I’m kinda new to SQL and been following some tutorial courses online. I want to compare the num_bikes_available at a station to the average num_bikes_available. My question is why cant it just show the average using the OUTER SELECT clause? Why do it need to be done using SUBQUERY? My Answer. Tutorial Answer. Answer Query SELECT AVG(num_bikes_available) FROM citibike_stations

Advertisement