-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10 pattern matchine questions.sql
More file actions
66 lines (49 loc) · 2.02 KB
/
10 pattern matchine questions.sql
File metadata and controls
66 lines (49 loc) · 2.02 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
use companydb;
create table sales(
customer_id int not null,
customer_name varchar(20),
product_name varchar(20),
product_category varchar(20),
sold_quantity int,
price decimal(10,2),
sale_date date);
drop table sales;
insert into sales values (1, 'Divya Prakash', 'Dell laptop', 'Electronics', 4, 32000, '2025-01-01'),
(2, 'Aditya Prakash', 'Drum', 'Instruments', 6, 12000, '2025-01-04'),
(3, 'Satya Prakash', 'Iron Rod', 'Iron', 10, 35000, '2025-01-05'),
(4, 'Ritesh KUmar', 'Car', 'Automobile', 1, 320000, '2025-01-01'),
(5, 'Raounak Rathore', 'Mobile', 'Electronics', 2, 15000, '2025-01-02');
select * from sales;
-- 1.alterRetrieve all employees whose customer names start with 'A'.
select * from sales
where customer_name like 'A%';
-- 2. Find all products with 'Electronics' anywhere in their names.
select * from sales
where product_category like '%Electronics%';
-- 3. Retrieve all customers whose names end with 'ash'.
select * from sales
where customer_name like '%ash';
-- 4. Fetch all users with a username of exactly 6 characters.
select * from sales
where customer_name like '_____________';
-- 5. Fetch all product category containing 'automobile'.
select * from sales
where product_category like '%automobile%';
-- 6.Find all products with a name that contains both 'a' and 'e'.
select * from sales
where product_name like '%a%p%' or product_name like '%p%a%';
-- 7.Find all price not starting with '1'.
select * from sales
where price not like '1%';
-- 8. Fetch all products with a name starting with either 'A' or 'D'.
select * from sales
where product_name like '[A]%';
-- 9.Find all customer names containing 1 consecutive vowels.
select * from sales
where customer_name REGEXP '[aeiou] {1}';
-- 10.Retrieve all products that contain the word 'Electronics' regardless of case.
select * from sales
where product_name like '%Electronics%';
-- 11.Retrieve all records where the customer id starts with '1'.
select * from sales
where customer_id like '1%';