-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLQuery1 - Instacart database - SQL BOOTCAMP CAPSTONE PROJECT.sql
More file actions
1201 lines (785 loc) · 21.5 KB
/
SQLQuery1 - Instacart database - SQL BOOTCAMP CAPSTONE PROJECT.sql
File metadata and controls
1201 lines (785 loc) · 21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-----------------------------------------------------------
-----------------------------------------------------------
-- SQL BOOTCAMP CAPSTONE PROJECT (Instacart Dataset) using Microsoft SQL
-- BY: GINO FREUD D. HOBAYAN
-----------------------------------------------------------
-----------------------------------------------------------
-----------------------------------------------------------
-----------------------------------------------------------
-- Data Definition Language (DDL)
-----------------------------------------------------------
-----------------------------------------------------------
CREATE DATABASE Instacart_DATABASE;
-----------------------------------------------------------
-- products TABLE (shape: 49.688, 4)
-----------------------------------------------------------
CREATE TABLE products
(
product_id VARCHAR(50) PRIMARY KEY NOT NULL,
product_name VARCHAR(250),
aisle_id INTEGER,
department_id INTEGER
);
--- Insert all the data from the CSV file into our table (COMMA DELIMITER)
BULK INSERT products
FROM "C:\Users\GINO\Desktop\SQL Capstone Project\InstaCart Online Grocery Basket Analysis Dataset\products.csv"
WITH (
FIELDTERMINATOR = ',', -- Use COMMA as the delimiter
ROWTERMINATOR = '\n',
FIRSTROW = 2 -- Skip the header row if present
);
-- Check the TABLE
SELECT TOP 600
*
FROM
products
ORDER BY
CAST(product_id AS INT);
-----------------------------------------------------------
-- orders TABLE (shape: 3.421.083, 7)
-----------------------------------------------------------
CREATE TABLE orders
(
order_id INTEGER PRIMARY KEY NOT NULL,
user_id INTEGER,
eval_set VARCHAR(100),
order_number INTEGER,
order_dow INTEGER,
order_hour_of_day INTEGER,
days_since_prior_order FLOAT
);
BULK INSERT orders
FROM "C:\Users\GINO\Desktop\SQL Capstone Project\InstaCart Online Grocery Basket Analysis Dataset\orders.csv"
WITH (
FIELDTERMINATOR = ',', -- Use COMMA as the delimiter
ROWTERMINATOR = '0x0a', -- Hexadecimal representation of line feed
FIRSTROW = 2 -- Skip the header row if present
);
-- Check the TABLE
SELECT TOP 1000
*
FROM
orders
ORDER BY
user_id
-- days_since_prior_order COLUMN HAS NULL VALUES.
-----------------------------------------------------------
-- order_product_prior TABLE (shape: 32.434.489, 4)
-----------------------------------------------------------
CREATE TABLE order_products__prior
(
order_id INT,
product_id VARCHAR(50),
add_to_cart_order INT,
reordered INT,
);
BULK INSERT order_products__prior
FROM "C:\Users\GINO\Desktop\SQL Capstone Project\InstaCart Online Grocery Basket Analysis Dataset\order_products__prior.csv"
WITH (
FIELDTERMINATOR = ',',
ROWTERMINATOR = '0x0a', -- Hexadecimal representation of line feed
FIRSTROW = 2
);
----------------------------------------------------------------------------------
-- SUCCESSFULLY CREATED A TABLE WITH 32,400,000 ROWS
-- QUERIES TAKE QUITE A WHILE
-- Check the TABLE
SELECT TOP 1000
*
FROM
order_products__prior
ORDER BY
order_id,
add_to_cart_order
-----------------------------------------------------------
-- order_product_train TABLE (shape: 1.384.617, 4)
-----------------------------------------------------------
CREATE TABLE order_products__train
(
order_id INT,
product_id VARCHAR(50),
add_to_cart_order INT,
reordered INT,
);
BULK INSERT order_products__train
FROM "C:\Users\GINO\Desktop\SQL Capstone Project\InstaCart Online Grocery Basket Analysis Dataset\order_products__train.csv"
WITH (
FIELDTERMINATOR = ',',
ROWTERMINATOR = '0x0a',
FIRSTROW = 2
);
-- Check the TABLE
SELECT TOP 1000
*
FROM
order_products__train
ORDER BY
order_id,
add_to_cart_order
-----------------------------------------------------------
-- aisles TABLE (shape: 134,2)
-----------------------------------------------------------
CREATE TABLE aisles
(
aisle_id INTEGER PRIMARY KEY,
aisle_name VARCHAR(255)
);
INSERT INTO aisles
(aisle_id, aisle_name)
VALUES
(1, 'prepared soups salads'),
(2, 'specialty cheeses'),
(3, 'energy granola bars'),
(4, 'instant foods'),
(5, 'marinades meat preparation'),
(6, 'other'),
(7, 'packaged meat'),
(8, 'bakery desserts'),
(9, 'pasta sauce'),
(10, 'kitchen supplies'),
(11, 'cold flu allergy'),
(12, 'fresh pasta'),
(13, 'prepared meals'),
(14, 'tofu meat alternatives'),
(15, 'packaged seafood'),
(16, 'fresh herbs'),
(17, 'baking ingredients'),
(18, 'bulk dried fruits vegetables'),
(19, 'oils vinegars'),
(20, 'oral hygiene'),
(21, 'packaged cheese'),
(22, 'hair care'),
(23, 'popcorn jerky'),
(24, 'fresh fruits'),
(25, 'soap'),
(26, 'coffee'),
(27, 'beers coolers'),
(28, 'red wines'),
(29, 'honeys syrups nectars'),
(30, 'latino foods'),
(31, 'refrigerated'),
(32, 'packaged produce'),
(33, 'kosher foods'),
(34, 'frozen meat seafood'),
(35, 'poultry counter'),
(36, 'butter'),
(37, 'ice cream ice'),
(38, 'frozen meals'),
(39, 'seafood counter'),
(40, 'dog food care'),
(41, 'cat food care'),
(42, 'frozen vegan vegetarian'),
(43, 'buns rolls'),
(44, 'eye ear care'),
(45, 'candy chocolate'),
(46, 'mint gum'),
(47, 'vitamins supplements'),
(48, 'breakfast bars pastries'),
(49, 'packaged poultry'),
(50, 'fruit vegetable snacks'),
(51, 'preserved dips spreads'),
(52, 'frozen breakfast'),
(53, 'cream'),
(54, 'paper goods'),
(55, 'shave needs'),
(56, 'diapers wipes'),
(57, 'granola'),
(58, 'frozen breads doughs'),
(59, 'canned meals beans'),
(60, 'trash bags liners'),
(61, 'cookies cakes'),
(62, 'white wines'),
(63, 'grains rice dried goods'),
(64, 'energy sports drinks'),
(65, 'protein meal replacements'),
(66, 'asian foods'),
(67, 'fresh dips tapenades'),
(68, 'bulk grains rice dried goods'),
(69, 'soup broth bouillon'),
(70, 'digestion'),
(71, 'refrigerated pudding desserts'),
(72, 'condiments'),
(73, 'facial care'),
(74, 'dish detergents'),
(75, 'laundry'),
(76, 'indian foods'),
(77, 'soft drinks'),
(78, 'crackers'),
(79, 'frozen pizza'),
(80, 'deodorants'),
(81, 'canned jarred vegetables'),
(82, 'baby accessories'),
(83, 'fresh vegetables'),
(84, 'milk'),
(85, 'food storage'),
(86, 'eggs'),
(87, 'more household'),
(88, 'spreads'),
(89, 'salad dressing toppings'),
(90, 'cocoa drink mixes'),
(91, 'soy lactosefree'),
(92, 'baby food formula'),
(93, 'breakfast bakery'),
(94, 'tea'),
(95, 'canned meat seafood'),
(96, 'lunch meat'),
(97, 'baking supplies decor'),
(98, 'juice nectars'),
(99, 'canned fruit applesauce'),
(100, 'missing'),
(101, 'air fresheners candles'),
(102, 'baby bath body care'),
(103, 'ice cream toppings'),
(104, 'spices seasonings'),
(105, 'doughs gelatins bake mixes'),
(106, 'hot dogs bacon sausage'),
(107, 'chips pretzels'),
(108, 'other creams cheeses'),
(109, 'skin care'),
(110, 'pickled goods olives'),
(111, 'plates bowls cups flatware'),
(112, 'bread'),
(113, 'frozen juice'),
(114, 'cleaning products'),
(115, 'water seltzer sparkling water'),
(116, 'frozen produce'),
(117, 'nuts seeds dried fruit'),
(118, 'first aid'),
(119, 'frozen dessert'),
(120, 'yogurt'),
(121, 'cereal'),
(122, 'meat counter'),
(123, 'packaged vegetables fruits'),
(124, 'spirits'),
(125, 'trail mix snack mix'),
(126, 'feminine care'),
(127, 'body lotions soap'),
(128, 'tortillas flat bread'),
(129, 'frozen appetizers sides'),
(130, 'hot cereal pancake mixes'),
(131, 'dry pasta'),
(132, 'beauty'),
(133, 'muscles joints pain relief'),
(134, 'specialty wines champagnes');
-- Check the TABLE
SELECT
*
FROM
aisles
-----------------------------------------------------------
-- departments TABLE (shape: 21,2)
-----------------------------------------------------------
CREATE TABLE departments
(
department_id INT PRIMARY KEY,
department VARCHAR(255) NOT NULL
);
INSERT INTO departments
(department_id, department)
VALUES
('1', 'frozen'),
('2', 'other'),
('3', 'bakery'),
('4', 'produce'),
('5', 'alcohol'),
('6', 'international'),
('7', 'beverages'),
('8', 'pets'),
('9', 'dry goods pasta'),
('10', 'bulk'),
('11', 'personal care'),
('12', 'meat seafood'),
('13', 'pantry'),
('14', 'breakfast'),
('15', 'canned goods'),
('16', 'dairy eggs'),
('17', 'household'),
('18', 'babies'),
('19', 'snacks'),
('20', 'deli'),
('21', 'missing');
-- Check the TABLE
SELECT
*
FROM
departments
-- TRIAL ------------------------------------------------------------------
-- MERGE THE IDENTICAL TABLES INTO ONE
CREATE TABLE all_order_products_combined
(
order_id INT,
product_id VARCHAR(50),
add_to_cart_order INT,
reordered INT
);
-- Insert data from order_products__prior
INSERT INTO all_order_products_combined (order_id, product_id, add_to_cart_order, reordered)
SELECT order_id, product_id, add_to_cart_order, reordered FROM order_products__prior;
-- Insert data from order_products__train
INSERT INTO all_order_products_combined (order_id, product_id, add_to_cart_order, reordered)
SELECT order_id, product_id, add_to_cart_order, reordered FROM order_products__train;
-----------------------------------------------
SELECT TOP 1000
*
FROM
all_order_products_combined
------------------------------------------------
SELECT
COUNT(*) AS total_num_of_rows
FROM
all_order_products_combined
-- 33,819,106 rows
-- TRIAL ------------------------------------------------------------------
-----------------------------------------------------------
-----------------------------------------------------------
-- DATA CLEANING
-- Data Manipulation Language (DML)
-----------------------------------------------------------
-----------------------------------------------------------
---------------------------------------------------------
-- CHECKING FOR DUPLICATE VALUES
---------------------------------------------------------
-- products TABLE
SELECT
product_name,
COUNT(*) AS total_num
FROM
products
GROUP BY
product_name
HAVING COUNT(product_name) > 1
/*
ANSWER: 101 DUPLICATE VALUES FOUND
Business Logic: Consider the business logic behind the data.
They look like duplicate values on paper,
but they have their own unique primary keys, they might be a different variation of the product
and might have orders connected with them and their unique primary key and product_id
I did not delete these, as it will affect the order counts, item popularity and other metrics
Deleting these duplicates could potentially disrupt the integrity of the data and impact the analysis.
*/
/*
Example: Bag of Oranges
1.) product_id = 4377
2.) product_id = 45231
*/
SELECT
*
FROM
products AS p
LEFT JOIN all_order_products_combined AS AOP
ON AOP.product_id = p.product_id
LEFT JOIN orders AS o
ON o.order_id = AOP.order_id
WHERE
p.product_name = 'Bag of Oranges'
---------------------------------------------------------
-- CHECKING FOR NULL VALUES
---------------------------------------------------------
-- orders TABLE
SELECT
COUNT(*) AS TOTAL_NUM_OF_RECORDS,
COUNT(order_id) AS non_null_order_id,
COUNT(user_id) AS non_null_user_id,
COUNT(eval_set) AS non_null_eval_set,
COUNT(order_number) AS non_null_order_number,
COUNT(order_dow) AS non_null_order_dow,
COUNT(order_hour_of_day) AS non_null_order_hour_of_day,
COUNT(days_since_prior_order) AS non_null_days_since_prior_order
FROM
orders;
-- 206,209 NULL VALUES FOUND on "orders" TABLE and "days_since_prior_order" COLUMN
SELECT
*
FROM
orders
WHERE
days_since_prior_order IS NULL
-- 206,209 null values CONFIRMED
-- orders TABLE
SELECT
COUNT(*) AS TOTAL_NUM_OF_RECORDS
FROM
orders
WHERE
order_number = 1
/*
Business Logic: Consider the business logic behind the data.
This is normal
It can be seen that for every users 1st order (order_number = 1)
the days_since_prior_order is NULL, which makes sense, since it's the very first order.
Therefore the NULL VALUES are valid.
Business Logic: Consider the business logic behind the data.
The NULL VALUES are valid.
Because they correspond to the first orders for each user,
where there is no prior order to calculate the time since.
In this case, it's not necessary to replace these null values with "NA" or any other value,
as they already hold a meaningful interpretation.
Keeping them as null values preserves the distinction between the first orders and subsequent orders.
We can also infer that there are 206,209 users/customers.
*/
---------------------------------------------------------
-- Leading and Trailing spaces using TRIM()?
---------------------------------------------------------
-------- aisles table - aisle_name
UPDATE aisles
SET aisle_name = TRIM(aisle_name);
-------- departments table - department
UPDATE departments
SET department = TRIM(department);
-------- products table - product_name
UPDATE products
SET product_name = TRIM(product_name);
--------- orders table - eval_set
UPDATE orders
SET eval_set = TRIM(eval_set);
/*
Find all string columns for TRIM()
I made sure that all string columns have no excessive spaces using TRIM() function.
*/
-----------------------------------------------------------
-----------------------------------------------------------
-- Data Query Language (DQL)
-----------------------------------------------------------
-----------------------------------------------------------
-- 1.) What are the most frequently ordered products?
SELECT TOP 10
p.product_name,
COUNT(o.order_number) AS ORDER_COUNT
FROM
products AS p
JOIN all_order_products_combined AS AOP
ON AOP.product_id = p.product_id
JOIN orders AS o
ON o.order_id = AOP.order_id
GROUP BY
p.product_name
ORDER BY
ORDER_COUNT DESC
/*
ANSWER:
product_name, ORDER_COUNT
Banana, 491291
Bag of Organic Bananas, 394930
Organic Strawberries, 275577
Organic Baby Spinach, 251705
Organic Hass Avocado, 220877
Organic Avocado, 184224
Large Lemon, 160792
Strawberries, 149445
Limes, 146660
Organic Whole Milk, 142813
*/
-- 2.) What are the least frequently ordered products?
SELECT TOP 10
p.product_name,
COUNT(o.order_number) AS ORDER_COUNT
FROM
products AS p
JOIN all_order_products_combined AS AOP
ON AOP.product_id = p.product_id
JOIN orders AS o
ON o.order_id = AOP.order_id
GROUP BY
product_name
ORDER BY
ORDER_COUNT ASC
/*
ANSWER:
(product_name, ORDER_COUNT)
'Swingtop' Premium Lager, 1
1 000 Mg Vitamin C Tangerine Grapefruit Effervescent Powdered Drink Mix, 1
11.3 Oz. Oreo Fudge Creme Double Chocolate, 1
12 Inch Taper Candle White, 1
7.04 Oz. Grahamfuls Banana Vanilla 8ct, 1
Aged Parmesan Cheese Sticks, 1
All Natural Stevia Liquid Extract Sweetener, 1
Anarchy For Her Daily Fragrance, 1
Anjou Pear Hand Soap, 1
Berry Sprouted Blend Cereal, 1
*/
-- 3.) Are there specific days of the week when orders are more frequent?
-- The days are anonymized, Day 0 could mean Sunday (or Monday if we go by ISO 8601)
SELECT
order_dow,
COUNT(order_number) AS ORDER_COUNT
FROM
orders
GROUP BY
order_dow
ORDER BY
order_dow ASC
/*
ANSWER:
(order_dow, ORDER_COUNT)
0 600905
1 587478
2 467260
3 436972
4 426339
5 453368
6 448761
*/
-- 4.) Are there specific hours of the day when orders are more frequent?
SELECT
order_hour_of_day,
COUNT(order_number) AS ORDER_COUNT
FROM
orders
GROUP BY
order_hour_of_day
ORDER BY
order_hour_of_day ASC
/*
ANSWER:
(order_hour_of_day, ORDER_COUNT)
0 22758
1 12398
2 7539
3 5474
4 5527
5 9569
6 30529
7 91868
8 178201
9 257812
10 288418
11 284728
12 272841
13 277999
14 283042
15 283639
16 272553
17 228795
18 182912
19 140569
20 104292
21 78109
22 61468
23 40043
*/
-- 5.) What are the most frequently REORDERED products?
SELECT TOP 10
p.product_name,
COUNT(AOP.product_id) AS REORDER_COUNT
FROM
products AS p
JOIN all_order_products_combined AS AOP
ON AOP.product_id = p.product_id
JOIN orders AS o
ON o.order_id = AOP.order_id
WHERE
AOP.reordered = 1
GROUP BY
p.product_name
ORDER BY
REORDER_COUNT DESC
/*
ANSWER:
(product_name, REORDER_COUNT)
Banana, 415166
Bag of Organic Bananas, 329275
Organic Strawberries, 214448
Organic Baby Spinach, 194939
Organic Hass Avocado, 176173
Organic Avocado, 140270
Organic Whole Milk, 118684
Large Lemon, 112178
Organic Raspberries, 109688
Strawberries, 104588
Organic fruits like Banana, Strawberries, and Avocados are frequently reordered
Milk is also frequently reordered.
These are the products that customer tend to stick with over time.
*/
-- 6.) Which products were never ordered / reordered?
SELECT
p.product_name,
COUNT(o.order_id) AS ORDER_COUNT
FROM
products AS p
LEFT JOIN all_order_products_combined AS AOP
ON AOP.product_id = p.product_id
LEFT JOIN orders AS o
ON o.order_id = AOP.order_id
GROUP BY
p.product_name
HAVING
COUNT(o.order_id) = 0
/*
ANSWER:
(product_name, ORDER_COUNT)
Protein Granola Apple Crisp 0
Single Barrel Kentucky Straight Bourbon Whiskey 0
Unpeeled Apricot Halves in Heavy Syrup 0
We used LEFT JOIN to include all products even if there are no corresponding orders.
We used GROUP BY p.product_name to count the orders for each product.
We used HAVING clause to filter out products that have a count of orders equal to 0, meaning they were never ordered or reordered.
*/
-- TRIAL -------------------------------------------------------------------
SELECT
--*
p.product_name,
COUNT(o.order_number) AS ORDER_COUNT
FROM
products AS p
JOIN all_order_products_combined AS AOP
ON AOP.product_id = p.product_id
JOIN orders AS o
ON o.order_id = AOP.order_id
GROUP BY
p.product_name
HAVING
o.order_number = 0
-- TRIAL -------------------------------------------------------------------
-- 7.) What aisles are the most popular? (by order count)
SELECT TOP 20
a.aisle_name,
COUNT(o.order_number) AS ORDER_COUNT
FROM
aisles AS a
JOIN products AS p
ON a.aisle_id = p.aisle_id
JOIN all_order_products_combined AS AOP
ON AOP.product_id = p.product_id
JOIN orders as o
ON o.order_id = AOP.order_id
GROUP BY
a.aisle_name
ORDER BY
ORDER_COUNT DESC