Mekki MOURADI

Data Analyst

Rabat, Maroc

À Propos

Data Analyst Junior avec une solide expérience en marketing numérique et des compétences approfondies dans l’utilisation de Microsoft Excel, SQL, Tableau Software et Python.

Complex Retrieval Queries with SQL

Liens

Compétences & Outils

Description du projet

Utiliser des Requêtes Complexes de Récupération avec SQL :
  • WHERE CLAUSE
  • JOIN STATEMENT
  • AGGREGATE QUERIES
  • NESTED QUERIES

Objectifs de l'analyse

  • Utiliser des Requêtes Complexes de Récupération avec SQL pour les besoins de l’analyse
  1. JOIN WITH THE WHERE CLAUSE
  1. Billing department has requested a list of our USA customers and their invoices with dates and totals
				
					SELECT  customer_id
		invoice_id,
		invoice_date,
		total
FROM invoice
WHERE billing_country='USA'
LIMIT 10;
				
			
invoice_idinvoice_datetotal
232009-01-1113.86
162009-02-190.99
172009-03-041.98
192009-03-041.98
212009-03-053.96
252009-03-065.94
192009-04-1413.86
172009-06-063.96
212009-06-075.94
272009-06-108.91
  1. Billing department also requested the first and last names
				
					SELECT  invoice.customer_id,
		first_name,
		last_name,
		invoice_id,
		invoice_date,
		total
FROM invoice, customer
WHERE billing_country='USA'
	AND invoice.customer_id=customer.customer_id
LIMIT 10;
				
			
customer_idfirst_namelast_nameinvoice_idinvoice_datetotal
23JohnGordon52009-01-1113.86
16FrankHarris132009-02-190.99
17JackSmith142009-03-041.98
19TimGoyer152009-03-041.98
21KathyChase162009-03-053.96
25VictorStevens172009-03-065.94
19TimGoyer262009-04-1413.86
17JackSmith372009-06-063.96
21KathyChase382009-06-075.94
27PatrickGray392009-06-108.91
  1. The Billing department has requested to add the unit price and quantity for each track purchased on each invoice
				
					SELECT  invoice.customer_id,
		first_name,
		last_name,
		invoice.invoice_id,
		invoice_date,
		total,
		track_id,
		unit_price,
		quantity
FROM invoice, customer, invoice_line
WHERE billing_country='USA'
	AND invoice.customer_id=customer.customer_id
	AND invoice.invoice_id=invoice_line.invoice_id
LIMIT 20;
				
			
customer_idfirst_namelast_nameinvoice_idinvoice_datetotaltrack_idunit_pricequantity
23JohnGordon52009-01-1113.86990.991
23JohnGordon52009-01-1113.861080.991
23JohnGordon52009-01-1113.861170.991
23JohnGordon52009-01-1113.861260.991
23JohnGordon52009-01-1113.861350.991
23JohnGordon52009-01-1113.861440.991
23JohnGordon52009-01-1113.861530.991
23JohnGordon52009-01-1113.861620.991
23JohnGordon52009-01-1113.861710.991
23JohnGordon52009-01-1113.861800.991
23JohnGordon52009-01-1113.861890.991
23JohnGordon52009-01-1113.861980.991
23JohnGordon52009-01-1113.862070.991
23JohnGordon52009-01-1113.862160.991
16FrankHarris132009-02-190.994620.991
17JackSmith142009-03-041.984630.991
17JackSmith142009-03-041.984640.991
19TimGoyer152009-03-041.984660.991
19TimGoyer152009-03-041.984680.991
21KathyChase162009-03-053.964700.991
  1. JOIN WITH THE JOIN STATEMENT
  1. Retrieve a list of the ship mode and how long (in seconds) it took to ship a product to a customer
				
					SELECT  name,
		title
FROM artist
JOIN album
ON artist.artist_id=album.artist_id
ORDER BY name, title
LIMIT 10;
				
			
nametitle
AC/DCFor Those About To Rock We Salute You
AC/DCLet There Be Rock
Aaron Copland & London Symphony OrchestraA Copland Celebration, Vol. I
Aaron GoldbergWorlds
Academy of St. Martin in the Fields & Sir Neville MarrinerThe World of Classical Favourites
Academy of St. Martin in the Fields Chamber Ensemble & Sir Neville MarrinerSir Neville Marriner: A Celebration
Academy of St. Martin in the Fields, John Birch, Sir Neville Marriner & Sylvia McNairFauré: Requiem, Ravel: Pavane & Others
Academy of St. Martin in the Fields, Sir Neville Marriner & Thurston DartBach: Orchestral Suites Nos. 1 - 4
AcceptBalls to the Wall
AcceptRestless and Wild
  1. AGGREGATE QUERIES
  1. Retrieve the number of invoices from each country
				
					SELECT billing_country, COUNT(*)
FROM invoice
GROUP BY billing_country;
				
			
billing_countrycount
Argentina7
Spain7
Italy7
Hungary7
India13
Czech Republic14
Belgium7
Sweden7
Chile7
Norway7
France35
USA91
United Kingdom21
Netherlands7
Brazil35
Austria7
Poland7
Australia7
Ireland7
Germany28
Denmark7
Canada56
Finland7
Portugal14
  1. Sales department want to know the top 10 customers who spend the most in our products
				
					SELECT  customer_id,
		SUM(total) AS total_spent
FROM invoice
GROUP BY customer_id
ORDER BY SUM(total) DESC
LIMIT 10;
				
			
customer_idtotal_spent
649.62
2647.62
5746.62
4645.62
4545.62
3743.62
2443.62
2843.62
2542.62
742.62
  1. Sales department wants to know the smallest and largest invoice total and average as well
				
					SELECT  customer_id,
		SUM(total) AS total_spent,
		MAX(total) AS largest_invoice,
		MIN(total) AS smallest_invoice,
		ROUND(AVG(total),2) AS average_invoice
FROM invoice
GROUP BY customer_id
ORDER BY SUM(total) DESC
LIMIT 10;
				
			
customer_idtotal_spentlargest_invoicesmallest_invoiceaverage_invoice
649.6225.860.997.09
2647.6223.860.996.80
5746.6217.910.996.66
4645.6221.860.996.52
4545.6221.860.996.52
3743.6214.910.996.23
2443.6215.860.996.23
2843.6213.860.996.23
2542.6218.860.996.09
742.6218.860.996.09
  1. NESTED QUERIES
  1. Sales department wants to know what invoices have totals that are above the average sales total
				
					SELECT  invoice_id,
		total
FROM invoice
WHERE total > (SELECT AVG(total) FROM invoice)
LIMIT 10;
				
			
invoice_idtotal
35.94
48.91
513.86
105.94
118.91
1213.86
175.94
188.91
1913.86
245.94
  1. Sales department wants a list of these customers
				
					SELECT  first_name,
		last_name
FROM customer
WHERE customer_id IN
(
	SELECT customer_id
	FROM invoice
	WHERE total>(SELECT AVG(total) FROM invoice)
)
LIMIT 10;
				
			
first_namelast_name
LuísGonçalves
LeonieKöhler
FrançoisTremblay
BjørnHansen
FrantišekWichterlová
HelenaHolý
AstridGruber
DaanPeeters
KaraNielsen
EduardoMartins