Untitled

mail@pastecode.io avatar
unknown
mysql
24 days ago
1.9 kB
3
Indexable
Never
-- Exercise 1: Select all workers with wcode = 12
SELECT 
    *
FROM
    test.workers
WHERE
    wcode = 12;

-- Exercise 2: Select all workers where name is 'sara'
SELECT 
    *
FROM
    test.workers
WHERE
    name = 'sara';

-- Exercise 3: Select names of workers who are older than 12
SELECT 
    name
FROM
    test.workers
WHERE
    age > 12;

-- Exercise 4: Select name and age of workers who started on specific dates
SELECT 
    name, age
FROM
    test.workers
WHERE
    start_date = '2003-12-12'
        OR start_date = '2004-07-19';

-- Exercise 5: Select all workers and order them by start_date
SELECT 
    *
FROM
    test.workers
ORDER BY start_date;

-- Exercise 6: Select age and marital status of worker named 'avi'
SELECT 
    age, married
FROM
    test.workers
WHERE
    name = 'avi';

-- Exercise 7: Select wcode and name of workers younger than 30
SELECT 
    wcode, name
FROM
    test.workers
WHERE
    age < 30;

-- Exercise 8: Select name and age of all workers and order by age
SELECT 
    name, age
FROM
    test.workers
ORDER BY age;

-- Exercise 9: Select all workers where name is either 'dan' or 'oren'
SELECT 
    *
FROM
    test.workers
WHERE
    name = 'dan' OR name = 'oren';

-- Exercise 10: Select all workers whose names start with 'a' and order by age
SELECT 
    *
FROM
    test.workers
WHERE
    name LIKE 'a%'
ORDER BY age;

-- Exercise 11: Get the maximum and minimum age of workers
SELECT 
    MAX(age) AS max_age, MIN(age) AS min_age
FROM
    test.workers;

-- Exercise 12: Select name and age of all workers and order by wcode in descending order
SELECT 
    name, age
FROM
    test.workers
ORDER BY wcode DESC;

-- Exercise 13: Select name and wcode of all married workers
SELECT 
    name, wcode
FROM
    test.workers
WHERE
    married = 1;

-- Exercise 14: Get the average age of all workers
SELECT 
    AVG(age) AS avg_age
FROM
    test.workers;
Leave a Comment