Skip to content

Өмнөх бичлэгийн жишээ болон бусад…

May 30, 2007

SELECT Statement ийн жишээ

SELECT column_name(s)
FROM table_name
SELECT * FROM Persons
SELECT DISTINCT column_name(s)
FROM table_name

Where Clause ашиглах

Where Clause – д олгох нөхцөлүүд
- +, <>, <, >=, <=
- Between : between 10 and 20
- in(set): Answer IN ('yes', 'no')
- LIKE : LIKE '%A%', 'A_%'
- NULL : IS NULL, IS NOT NULL
SELECT column FROM table
WHERE column operator value

Зөв бичлэг:
SELECT * FROM Persons WHERE FirstName='Болор'
Буруу:
SELECT * FROM Persons WHERE FirstName=Болор
Зөв бичлэг:
SELECT * FROM Persons WHERE Year>1981
Буруу:
SELECT * FROM Persons WHERE Year>'1981'
LIKE Condition
SELECT column FROM table
WHERE column LIKE pattern

INSERT statement
INSERT INTO table_name
VALUES (value1, value2,....)
INSERT INTO table_name (column1, column2,...)
VALUES (value1, value2,....)
INSERT INTO Persons 
VALUES ('Бундага', 'Болор', '24', 'Улааныаатар')
INSERT INTO Persons (LastName, Address)
VALUES ('Бундага', 'СХД')

UPDATE Statement
UPDATE table_name
SET column_name = new_value
WHERE column_name = some_value
Update column in a row
UPDATE Person SET FirstName = 'Ариун'
WHERE LastName = 'Чулуунхvv'
Update several column in a row
UPDATE Person
SET Address = 'ЧД', City = 'Улаанбаатар'
WHERE LastName = 'Бундага'

DELETE statement
DELETE FROM table_name
WHERE column_name = some_value
DELETE FROM Person WHERE LastName = 'Бундага'
DELETE FROM table_name
or
DELETE * FROM table_name

ORDER By 
SELECT Company, OrderNumber FROM Orders
ORDER BY Company DESC
COUNT(*)
        COUNT(expression)
        MAX(expression)
        MIN(expression)
        SUM(expression)
        AVG(expression) – dundaj
Ex:
        Select [columnname], Bulegleh func
        from [table name]
        Group by [columnname]
select avg(unitprice) 'dundaj'
        from Products
One Comment leave one →
  1. June 2, 2007 11:21 am

    Би SQL дээр лайтай query бичдэг шд. Өгөгдлийн сантай ажиллах тал дээр сайн шүү. Хичээл амраад би гэдэг хүн ажилгүйчүүдийн эгнээнд нэгдчихээд байнаа. Надад санал болгох ажил байна уу? гэсэн хэхэхэхэ

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: