Translate

Saturday, 20 December 2025

Sql Vibe coding - AI Data Analytics Mastery In Telugu

 "Act as an expert SQL instructor. I am a complete beginner using Microsoft SQL Server.

First, provide me with a 'starter kit' code block that creates a table and populates it with sample data so I can practice immediately.

Next, guide me through a 10-step lesson plan covering the most basic SQL commands (like SELECT, WHERE, ORDER BY, COUNT, etc.). For each step, explain the concept simply and provide the query I should run against my new table."


"I am a beginner using Microsoft SQL Server and want to learn the basics. Since I don't have a dataset, please start by generating a SQL query to create a sample table (like 'Employees') and insert dummy data into it.

Once the data is ready, guide me through the 10 most basic SQL queries (such as Select, Filter, Sort, and Aggregate) to help me understand how SQL works. Include the code, the output, and a short explanation for each."


"నేను SQL నేర్చుకోవడానికి కొత్త. నేను Microsoft SQL Server వాడుతున్నాను. నాకు బేసిక్ అవగాహన కోసం 10 ముఖ్యమైన SQL క్వెరీస్ ఇవ్వగలరా? నా దగ్గర ప్రస్తుతం డేటా ఏమీ లేదు, కాబట్టి ముందుగా ఒక టేబుల్ (table) క్రియేట్ చేయడానికి మరియు అందులో కొంత సాంపిల్ డేటా (sample data) ఇన్సర్ట్ చేయడానికి కోడ్ ఇవ్వండి, తద్వారా నేను ప్రాక్టీస్ చేయగలను."

----------------------------

"Vibe coding" is a fantastic way to learn—it's essentially using the LLM as a pair programmer, a mentor, and a sandbox all at once. Instead of passively watching videos, you are interacting, coding, and getting instant feedback.

Here is a roadmap and specific copy-paste prompts to help you master SQL (specifically T-SQL for Microsoft SQL Server) using Gemini.


The "Vibe Coding" Workflow

To get the most out of this, follow this loop for every prompt below:

  1. Paste the prompt.

  2. Read the concept the AI explains.

  3. Write the code (even if it's wrong!) and paste it back to the AI.

  4. Ask for a "Vibe Check": Ask the AI to rate your code, optimize it, or explain why it works.


Phase 1: The Setup & Basics (The Foundation)

Goal: Get SQL Server running and write your first query.

Prompt 1: The Environment

"Act as a friendly IT mentor. Guide me through installing SQL Server Express and SSMS (SQL Server Management Studio) on my machine. Explain it like I'm 5. Once installed, help me create a dummy database called LibraryDB with a simple table called Books."

Prompt 2: The Select Statement (The Bread & Butter)

"I want to learn how to view data. Explain the SELECT, FROM, and WHERE clauses using a metaphor about ordering food from a menu. Give me 3 challenges to fetch specific books from my LibraryDB (e.g., 'Find all books written by 'Tolkien'). Don't give me the code yet—wait for me to try."


Phase 2: Shaping Data (The Builder)

Goal: Learn how to connect data and change it.


Shutterstock

Prompt 3: The Art of Joining

"I am confused about Joins. Act as a Senior SQL Developer. Explain the difference between INNER JOIN, LEFT JOIN, and FULL OUTER JOIN using a visual description. Create a second table called Authors and link it to Books. Then, give me a puzzle to list every book alongside its author's name. If an author has no books, show them anyway."

Prompt 4: CRUD Operations

"I need to manipulate data. Teach me INSERT, UPDATE, and DELETE. Give me a 'dangerous' scenario where I might accidentally delete everything if I forget a WHERE clause, and explain how to prevent it. Then, ask me to write a query that updates the price of all 'Fantasy' books by 10%."


Phase 3: Aggregation & Grouping (The Analyst)

Goal: Summarize data for reports.

Prompt 5: Group By and Having

"I want to generate reports. Teach me about GROUP BY, COUNT, SUM, and the HAVING clause. Use a real-world business example, like calculating total sales per region. Then, challenge me to write a query for my LibraryDB that shows which authors have written more than 3 books."


Phase 4: Advanced T-SQL (The Wizard)

Goal: Write logic, not just queries.

Prompt 6: Stored Procedures (Vibe Check)

"I'm ready for automation. Explain what a Stored Procedure is and why it's better than running raw SQL queries (mention security and speed). ask me to write a procedure called AddNewBook that takes parameters (Title, Author, Price). When I paste my code, critique it for 'SQL Injection' vulnerabilities."

Prompt 7: Window Functions (The Pro Move)

"Explain Window Functions (like ROW_NUMBER() and RANK()) to me. Why are they different from GROUP BY? Show me how to find the 'Top 3 most expensive books' in each genre without collapsing the rows."


Phase 5: The "Boss Fight" (Real World Project)

Goal: Combine everything into a portfolio-worthy script.

Prompt 8: The E-Commerce Simulator

"Let's build a final project. Act as a Product Manager. Outline a schema for a simple E-Commerce Store (Customers, Orders, OrderItems, Products).

  1. Give me the DDL (Create scripts) to set it up.

  2. Ask me to write a complex query that finds the 'VIP Customers' (those who spent over $500 last month).

  3. After I solve it, show me how to optimize it using Indexes."


Tips for "Vibe Coding" with SQL Server

  • Ask "Why?": If the AI gives you code, always follow up with: "Why did you use VARCHAR(50) instead of NVARCHAR(50)?" or "Why is UNION ALL faster than UNION?"

  • Break it: Intentionally write bad code and ask: "What happens if I run this? Will it crash?"

  • Request Data: If you don't want to type out manual data, ask the AI: "Generate a script to insert 20 rows of realistic dummy data into my Books table."

------------------


Vibe coding" అనేది నేర్చుకోవడానికి ఒక అద్భుతమైన పద్ధతి. ఇది కేవలం వీడియోలు చూడటం కాకుండా, AIని (Gemini) ఒక ఫ్రెండ్‌లా, గైడ్‌లా వాడుకుంటూ ప్రాక్టీస్ చేయడం. మీరు రాసిన కోడ్‌కి AI నుండి వెంటనే ఫీడ్‌బ్యాక్ తీసుకుంటూ నేర్చుకోవచ్చు.

Geminiని ఉపయోగించి SQL (ముఖ్యంగా SQL Server కోసం T-SQL) నేర్చుకోవడానికి ఇక్కడ ఒక రోడ్‌మ్యాప్ మరియు మీరు నేరుగా వాడగలిగే కాపీ-పేస్ట్ ప్రాంప్ట్స్ (Prompts) ఉన్నాయి.


"Vibe Coding" పద్ధతిని ఇలా పాటించండి

ప్రతి దశలోనూ ఈ లూప్‌ని ఫాలో అవ్వండి:

  1. ప్రాంప్ట్‌ని పేస్ట్ చేయండి.

  2. కాన్సెప్ట్‌ని చదవండి: AI చెప్పిన విషయాన్ని అర్థం చేసుకోండి.

  3. కోడ్ రాయండి: తప్పు అయినా పర్లేదు! మీ సొంతంగా కోడ్ రాసి AIకి పంపండి.

  4. "Vibe Check" అడగండి: మీ కోడ్ ఎలా ఉందో, దాన్ని ఎలా మెరుగుపరచవచ్చో, లేదా ఎందుకు పని చేస్తుందో వివరించమని AIని అడగండి.


దశ 1: సెటప్ & బేసిక్స్ (పునాది)

లక్ష్యం: SQL Server రన్ చేయడం మరియు మీ మొదటి క్వెరీ రాయడం.

Prompt 1: ఎన్విరాన్మెంట్ సెటప్ (The Environment)

"ఒక ఫ్రెండ్లీ IT మెంటార్‌లా (Guru) ప్రవర్తించు. నా కంప్యూటర్‌లో SQL Server Express మరియు SSMS (SQL Server Management Studio) ఇన్‌స్టాల్ చేయడానికి గైడ్ చేయి. ఒక చిన్న పిల్లాడికి చెప్పినట్లు వివరంగా చెప్పు. ఇన్‌స్టాల్ అయ్యాక, LibraryDB అనే డమ్మీ డేటాబేస్ మరియు అందులో Books అనే సింపుల్ టేబుల్ క్రియేట్ చేయడంలో సహాయం చేయి."

Prompt 2: సెలెక్ట్ స్టేట్‌మెంట్ (The Select Statement)

"నేను డేటాను ఎలా చూడాలో (View) నేర్చుకోవాలి. SELECT, FROM, మరియు WHERE గురించి ఒక హోటల్ మెనూ నుండి ఫుడ్ ఆర్డర్ చేసే ఉదాహరణతో వివరించు. నా LibraryDB నుండి కొన్ని పుస్తకాలను వెతకడానికి నాకు 3 ఛాలెంజ్‍లు ఇవ్వు (ఉదాహరణకు: 'Tolkien' రాసిన పుస్తకాలను కనుగొనడం). కోడ్ ఇప్పుడే ఇవ్వకు—నేను ప్రయత్నించే వరకు ఆగు."


దశ 2: డేటాను తీర్చిదిద్దడం (The Builder)

లక్ష్యం: డేటాను కనెక్ట్ చేయడం మరియు మార్చడం నేర్చుకోవడం.

Prompt 3: జాయిన్స్ (The Art of Joining)

"నాకు Joins గురించి కన్ఫ్యూజన్‌గా ఉంది. సీనియర్ SQL డెవలపర్‌లా వివరించు. INNER JOIN, LEFT JOIN, మరియు FULL OUTER JOIN మధ్య తేడాను బొమ్మలతో వివరించినట్లు చెప్పు. Authors అనే మరో టేబుల్ క్రియేట్ చేసి దాన్ని Booksతో లింక్ చేయి. తర్వాత, ప్రతి పుస్తకం పక్కన దాని రచయిత పేరు వచ్చేలా ఒక పజిల్ ఇవ్వు. ఒకవేళ రచయితకు పుస్తకాలు లేకపోయినా ఆ పేరు చూపించాలి."

Prompt 4: డేటా మార్పులు (CRUD Operations)

"నేను డేటాను మార్చాలి. INSERT, UPDATE, మరియు DELETE గురించి నేర్పించు. నేను WHERE క్లాజ్ మర్చిపోతే డేటా మొత్తం ఎలా డిలీట్ అయిపోతుందో ఒక 'ప్రమాదకరమైన' ఉదాహరణతో వివరించు. తర్వాత, 'Fantasy' పుస్తకాల ధరను 10% పెంచే క్వెరీ రాయమని నన్ను అడుగు."


దశ 3: గ్రూపింగ్ & రిపోర్టింగ్ (The Analyst)

లక్ష్యం: రిపోర్ట్స్ కోసం డేటాను సమ్మరైజ్ చేయడం.

Prompt 5: Group By మరియు Having

"నేను రిపోర్ట్స్ తయారు చేయాలి. GROUP BY, COUNT, SUM, మరియు HAVING క్లాజ్ గురించి నేర్పించు. ఒక రియల్ వరల్డ్ బిజినెస్ ఉదాహరణ (ఉదా: ప్రాంతాల వారీగా అమ్మకాలు) చెప్పు. తర్వాత, నా LibraryDB కోసం 3 కంటే ఎక్కువ పుస్తకాలు రాసిన రచయితలను చూపే క్వెరీ రాయమని నాకు ఛాలెంజ్ ఇవ్వు."


దశ 4: అడ్వాన్స్డ్ T-SQL (The Wizard)

లక్ష్యం: కేవలం క్వెరీలే కాకుండా, లాజిక్ రాయడం.

Prompt 6: స్టోర్డ్ ప్రొసీజర్స్ (Stored Procedures)

"నేను ఆటోమేషన్ కోసం రెడీగా ఉన్నాను. Stored Procedure అంటే ఏమిటి? మామూలు SQL క్వెరీల కంటే ఇది ఎందుకు బెటర్? (సెక్యూరిటీ మరియు స్పీడ్ గురించి చెప్పు). AddNewBook అనే ప్రొసీజర్ రాయమని నన్ను అడుగు (దీనికి Title, Author, Price పారామీటర్లు ఉండాలి). నేను కోడ్ పేస్ట్ చేశాక, అందులో 'SQL Injection' లోపాలు ఉంటే చెప్పు."

Prompt 7: విండో ఫంక్షన్స్ (Window Functions)

"Window Functions (ఉదాహరణకు ROW_NUMBER(), RANK()) గురించి వివరించు. ఇవి GROUP BYకి ఎలా భిన్నం? ప్రతి జానర్ (Genre)లో టాప్ 3 ఖరీదైన పుస్తకాలను... మిగతా రోస్ (Rows) మిస్ కాకుండా ఎలా కనుగొనాలో నేర్పించు."


దశ 5: "బాస్ ఫైట్" (రియల్ వరల్డ్ ప్రాజెక్ట్)

లక్ష్యం: అన్నీ కలిపి ఒక ప్రాజెక్ట్ చేయడం.

Prompt 8: ఈ-కామర్స్ సిమ్యులేటర్

"ఇప్పుడు ఒక ఫైనల్ ప్రాజెక్ట్ చేద్దాం. ప్రొడక్ట్ మేనేజర్‌లా ప్రవర్తించు. ఒక E-Commerce Store (Customers, Orders, OrderItems, Products) కోసం స్కీమా ప్లాన్ చేయి.

  1. దీన్ని సెటప్ చేయడానికి స్క్రిప్ట్స్ (DDL) ఇవ్వు.

  2. గత నెలలో $500 కంటే ఎక్కువ ఖర్చు చేసిన 'VIP Customers'ని కనుగొనే ఒక కాంప్లెక్స్ క్వెరీ రాయమని అడుగు.

  3. నేను రాశాక, Indexes వాడి దాన్ని ఎలా ఆప్టిమైజ్ (Speed up) చేయాలో చెప్పు."


SQL Server "Vibe Coding" టిప్స్

  • "ఎందుకు?" (Why?) అని అడగండి: AI ఏదైనా కోడ్ ఇస్తే, "నువ్వు VARCHAR బదులు NVARCHAR ఎందుకు వాడావు?" అని అడగండి.

  • బ్రేక్ చేయండి: కావాలనే తప్పు కోడ్ రాసి, "ఇది రన్ చేస్తే ఏమవుతుంది? క్రాష్ అవుతుందా?" అని అడగండి.

  • డేటా అడగండి: మాన్యువల్ గా టైప్ చేయడం కష్టంగా ఉంటే, "నా Books టేబుల్ కోసం 20 డమ్మీ రికార్డ్స్ ఇన్సర్ట్ చేయడానికి స్క్రిప్ట్ ఇవ్వు" అని అడగండి.

---------------------------

Welcome to the world of databases! As your instructor, I’m excited to guide you. SQL (Structured Query Language) is the standard language for talking to databases, and Microsoft SQL Server is one of the most powerful platforms to use it on.

We will focus on the absolute essentials. By the end of this session, you will know how to find, filter, and sort data with confidence.


🛠️ Your SQL Starter Kit

Before we learn, we need data to play with. Copy the code block below, paste it into your SQL Server query window, and press Execute (or F5).

This will create a table representing a small Bookstore Inventory.

SQL
-- 1. Create a table to store book information
CREATE TABLE Books (
    BookID INT PRIMARY KEY,
    Title VARCHAR(100),
    Author VARCHAR(50),
    Genre VARCHAR(30),
    Price DECIMAL(10, 2),
    StockQuantity INT,
    PublishedYear INT
);

-- 2. Populate the table with sample data
INSERT INTO Books (BookID, Title, Author, Genre, Price, StockQuantity, PublishedYear)
VALUES 
(1, 'The Great Gatsby', 'F. Scott Fitzgerald', 'Classic', 10.99, 50, 1925),
(2, '1984', 'George Orwell', 'Dystopian', 8.99, 100, 1949),
(3, 'The Hobbit', 'J.R.R. Tolkien', 'Fantasy', 15.50, 20, 1937),
(4, 'Harry Potter', 'J.K. Rowling', 'Fantasy', 20.00, 15, 1997),
(5, 'Becoming', 'Michelle Obama', 'Memoir', 18.00, 60, 2018),
(6, 'Steve Jobs', 'Walter Isaacson', 'Biography', 22.50, 12, 2011),
(7, 'The Catcher in the Rye', 'J.D. Salinger', 'Classic', 9.50, 8, 1951),
(8, 'Dune', 'Frank Herbert', 'Sci-Fi', 12.00, 45, 1965);

🎓 The 10-Step Lesson Plan

Now that your data is ready, let's start querying! Run these commands one by one.

Step 1: Retrieving Everything (SELECT *)

The most basic command. The asterisk (*) is a wildcard that means "all columns."

  • Concept: "Show me every single piece of data in the Books table."

SQL
SELECT * FROM Books;

Step 2: Selecting Specific Columns

Often, you don't need all the data. You only want specific details, like the title and price.

  • Concept: "Show me only the Title and Price for every book."

SQL
SELECT Title, Price 
FROM Books;

Step 3: Filtering by Numbers (WHERE)

We use the WHERE clause to filter results. Let's find cheaper books.

  • Concept: "Show me all details for books that cost less than $12.00."

SQL
SELECT * FROM Books 
WHERE Price < 12.00;

Step 4: Filtering by Text (WHERE)

We can also filter for text. Note: In SQL, text must always be wrapped in single quotes (').

  • Concept: "Show me all the books where the Genre is 'Fantasy'."

SQL
SELECT * FROM Books 
WHERE Genre = 'Fantasy';

Step 5: Sorting Results (ORDER BY)

Data usually comes out in the order it was entered. Let's organize it alphabetically or numerically.

  • Concept: "Show me all books, sorted by Price from highest to lowest (Descending)."

SQL
SELECT Title, Price 
FROM Books 
ORDER BY Price DESC;

(Note: Use ASC for ascending order, though it is the default behavior if you leave it out.)

Step 6: Limiting Results (TOP)

In Microsoft SQL Server, we use TOP to limit how many rows we get back. This is useful when you have millions of rows but only want a sample.

  • Concept: "Show me the top 3 most expensive books."

SQL
SELECT TOP 3 Title, Price
FROM Books
ORDER BY Price DESC;

Step 7: Counting Data (COUNT)

Sometimes you don't want the actual records; you just want to know how many there are.

  • Concept: "Count how many books we have in the 'Classic' genre."

SQL
SELECT COUNT(*) 
FROM Books 
WHERE Genre = 'Classic';

Step 8: Basic Math (SUM and AVG)

SQL can do math for you. Let's look at our inventory value.

  • Concept: "What is the average price of a book in our store?"

SQL
SELECT AVG(Price) 
FROM Books;

Step 9: Pattern Matching (LIKE)

Sometimes you don't know the exact title, but you know part of it. We use the % symbol as a wildcard to match anything.

  • Concept: "Find any book that has the word 'The' anywhere in the title."

SQL
SELECT * FROM Books 
WHERE Title LIKE '%The%';

Step 10: Grouping Data (GROUP BY)

This is slightly more advanced but very powerful. It allows you to categorize data and perform math on each category.

  • Concept: "Show me each Genre and the count of books within that genre."

SQL
SELECT Genre, COUNT(*) 
FROM Books 
GROUP BY Genre;
---------------

డేటాబేస్ ప్రపంచానికి స్వాగతం! మీ ఇన్‌స్ట్రక్టర్‌గా, మీకు సహాయం చేయడానికి నేను సిద్ధంగా ఉన్నాను. SQL (Structured Query Language) అనేది డేటాబేస్‌లతో మాట్లాడటానికి ఉపయోగించే ప్రామాణిక భాష. Microsoft SQL Server దీనిని ఉపయోగించడానికి ఒక శక్తివంతమైన వేదిక.

మనం ఇప్పుడు SQLలోని అత్యంత ముఖ్యమైన అంశాలపై దృష్టి పెడదాం. ఈ సెషన్ చివరి నాటికి, మీరు డేటాను ఎలా వెతకాలి, ఫిల్టర్ చేయాలి మరియు ఎలా ఆర్డర్ చేయాలో నేర్చుకుంటారు.


🛠️ మీ SQL స్టార్టర్ కిట్ (Starter Kit)

మనం నేర్చుకోవడం ప్రారంభించే ముందు, ప్రాక్టీస్ చేయడానికి మనకు కొంత డేటా అవసరం. క్రింద ఉన్న కోడ్ బ్లాక్‌ను కాపీ చేసి, మీ SQL Server విండోలో పేస్ట్ చేసి, Execute (లేదా F5) నొక్కండి.

ఇది ఒక చిన్న పుస్తకాల షాపు (Bookstore) డేటాను సృష్టిస్తుంది.

SQL

-- 1. పుస్తకాల సమాచారాన్ని భద్రపరచడానికి ఒక టేబుల్‌ను సృష్టించడం
CREATE TABLE Books (
    BookID INT PRIMARY KEY,
    Title VARCHAR(100),
    Author VARCHAR(50),
    Genre VARCHAR(30),
    Price DECIMAL(10, 2),
    StockQuantity INT,
    PublishedYear INT
);

-- 2. టేబుల్‌లో శాంపిల్ డేటాను నింపడం
INSERT INTO Books (BookID, Title, Author, Genre, Price, StockQuantity, PublishedYear)
VALUES 
(1, 'The Great Gatsby', 'F. Scott Fitzgerald', 'Classic', 10.99, 50, 1925),
(2, '1984', 'George Orwell', 'Dystopian', 8.99, 100, 1949),
(3, 'The Hobbit', 'J.R.R. Tolkien', 'Fantasy', 15.50, 20, 1937),
(4, 'Harry Potter', 'J.K. Rowling', 'Fantasy', 20.00, 15, 1997),
(5, 'Becoming', 'Michelle Obama', 'Memoir', 18.00, 60, 2018),
(6, 'Steve Jobs', 'Walter Isaacson', 'Biography', 22.50, 12, 2011),
(7, 'The Catcher in the Rye', 'J.D. Salinger', 'Classic', 9.50, 8, 1951),
(8, 'Dune', 'Frank Herbert', 'Sci-Fi', 12.00, 45, 1965);

🎓 10-దశల పాఠ్య ప్రణాళిక (Lesson Plan)

ఇప్పుడు మన డేటా సిద్ధంగా ఉంది కాబట్టి, క్వెరీ (Query) చేయడం ప్రారంభిద్దాం! ఈ కమాండ్లను ఒక్కొక్కటిగా రన్ చేయండి.

1వ దశ: మొత్తం డేటాను పొందడం (SELECT *)

ఇది అత్యంత ప్రాథమిక కమాండ్. ఆస్టరిస్క్ (*) గుర్తుకు అర్థం “అన్ని కాలమ్స్ (Columns)” అని.

  • కాన్సెప్ట్: “Books టేబుల్‌లో ఉన్న ప్రతి డేటాను నాకు చూపించు.”

SQL

SELECT * FROM Books;

2వ దశ: నిర్దిష్ట కాలమ్స్ ఎంచుకోవడం

చాలా సార్లు మీకు మొత్తం డేటా అవసరం ఉండదు. మీకు కేవలం పుస్తకం పేరు మరియు ధర వంటి వివరాలు మాత్రమే కావాలి అనుకుందాం.

  • కాన్సెప్ట్: “ప్రతి పుస్తకం యొక్క Title (పేరు) మరియు Price (ధర) మాత్రమే చూపించు.”

SQL

SELECT Title, Price 
FROM Books;

3వ దశ: సంఖ్యల ద్వారా ఫిల్టర్ చేయడం (WHERE)

ఫలితాలను ఫిల్టర్ చేయడానికి మనం WHERE క్లాజ్‌ని ఉపయోగిస్తాము. తక్కువ ధర గల పుస్తకాలను వెతుకుదాం.

  • కాన్సెప్ట్: “ధర $12.00 కంటే తక్కువ ఉన్న పుస్తకాల వివరాలను చూపించు.”

SQL

SELECT * FROM Books 
WHERE Price < 12.00;

4వ దశ: టెక్స్ట్ ద్వారా ఫిల్టర్ చేయడం (WHERE)

మనం టెక్స్ట్ (Text) కోసం కూడా ఫిల్టర్ చేయవచ్చు. గమనిక: SQLలో, టెక్స్ట్ ఎల్లప్పుడూ సింగిల్ కోట్స్ (') మధ్యలో ఉండాలి.

  • కాన్సెప్ట్: “Genre (రకం) ‘Fantasy’ గా ఉన్న పుస్తకాలను చూపించు.”

SQL

SELECT * FROM Books 
WHERE Genre = 'Fantasy';

5వ దశ: ఫలితాలను వరుస క్రమంలో అమర్చడం (ORDER BY)

సాధారణంగా డేటా ఎంటర్ చేసిన ఆర్డర్ లో వస్తుంది. మనం దానిని అక్షర క్రమంలో లేదా సంఖ్యల ఆధారంగా అమర్చవచ్చు.

  • కాన్సెప్ట్: “పుస్తకాలను Price (ధర) ఆధారంగా ఎక్కువ నుండి తక్కువకు (Descending) అమర్చి చూపించు.”

SQL

SELECT Title, Price 
FROM Books 
ORDER BY Price DESC;

(గమనిక: తక్కువ నుండి ఎక్కువకు కావాలంటే ASC వాడాలి, కానీ ఏమీ ఇవ్వకపోతే అదే డిఫాల్ట్‌గా వస్తుంది.)

6వ దశ: ఫలితాలను పరిమితం చేయడం (TOP)

Microsoft SQL Serverలో, మనకు ఎన్ని ఫలితాలు కావాలో చెప్పడానికి TOP వాడతాము. మీ దగ్గర వేల కొద్దీ రికార్డులు ఉండి, కేవలం కొన్ని మాత్రమే చూడాలనుకున్నప్పుడు ఇది ఉపయోగపడుతుంది.

  • కాన్సెప్ట్: “అత్యంత ఖరీదైన మొదటి 3 పుస్తకాలను చూపించు.”

SQL

SELECT TOP 3 Title, Price
FROM Books
ORDER BY Price DESC;

7వ దశ: డేటాను లెక్కించడం (COUNT)

కొన్నిసార్లు మీకు రికార్డులు అవసరం లేదు; కేవలం అవి ఎన్ని ఉన్నాయో తెలుసుకోవాలి.

  • కాన్సెప్ట్: “‘Classic’ జానర్‌లో మన దగ్గర ఎన్ని పుస్తకాలు ఉన్నాయో లెక్కించు.”

SQL

SELECT COUNT(*) 
FROM Books 
WHERE Genre = 'Classic';

8వ దశ: ప్రాథమిక గణితం (SUM మరియు AVG)

SQL మీ కోసం గణితం చేయగలదు. మన ఇన్వెంటరీ విలువను చూద్దాం.

  • కాన్సెప్ట్: “మన స్టోర్‌లోని పుస్తకాల సగటు (Average) ధర ఎంత?”

SQL

SELECT AVG(Price) 
FROM Books;

9వ దశ: పాటర్న్ మ్యాచింగ్ (LIKE)

కొన్నిసార్లు మీకు ఖచ్చితమైన పేరు తెలియదు, కానీ అందులో కొంత భాగం తెలుసు. ఏదైనా సరిపోల్చడానికి మనం % గుర్తును వైల్డ్‌కార్డ్‌గా ఉపయోగిస్తాము.

  • కాన్సెప్ట్: “టైటిల్‌లో ఎక్కడైనా ‘The’ అనే పదం ఉన్న పుస్తకాలను వెతుకు.”

SQL

SELECT * FROM Books 
WHERE Title LIKE '%The%';

10వ దశ: డేటాను గ్రూప్ చేయడం (GROUP BY)

ఇది కొంచెం అడ్వాన్స్‌డ్ కానీ చాలా శక్తివంతమైనది. ఇది డేటాను వర్గీకరించి, ప్రతి వర్గంపై గణితాన్ని చేయడానికి అనుమతిస్తుంది.

  • కాన్సెప్ట్: “ప్రతి Genre (జానర్) పేరు మరియు ఆ జానర్‌లో ఉన్న పుస్తకాల సంఖ్యను చూపించు.”

SQL

SELECT Genre, COUNT(*) 
FROM Books 
GROUP BY Genre;



No comments:

Post a Comment

Note: only a member of this blog may post a comment.