-- Ma'lumotlar bazasini yaratish
CREATE DATABASE IF NOT EXISTS mydatabase;
USE mydatabase;
-- Foydalanuvchi jadvalini yaratish
CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL,
email VARCHAR(100) NOT NULL,
age INT
);
-- Ma'lumotlarni kiritish
INSERT INTO users (username, email, age) VALUES
('john_doe', 'john@example.com', 25),
('jane_doe', 'jane@example.com', 30),
('alice', 'alice@example.com', 22);
-- Ma'lumotlarni ko'rish
SELECT * FROM users;
-- WHERE, AND, OR, NOT, LIKE bilan so'rovlar
-- Misol: 30 yoshdan katta yoki 'john' nomli foydalanuvchilarni tanlash
SELECT * FROM users WHERE age > 30 OR username LIKE '%john%';
-- Misol: 22 dan 30 gacha bo'lgan yoshdagi foydalanuvchilarni tanlash
SELECT * FROM users WHERE age BETWEEN 22 AND 30;
-- Misol: 30 yoshdan kichik foydalanuvchilarni tanlash
SELECT * FROM users WHERE NOT age > 30;
-- Jadvaldagi ma'lumotlarni o'zgartirish
UPDATE users SET age = 32 WHERE username = 'john_doe';
-- Ma'lumotni o'chirish
DELETE FROM users WHERE username = 'alice';
Dostları ilə paylaş: |