The use of the Yaer function (query number 108 students, all students born in the same year, Sno, sname and sbirthday column) _table

Source: Internet
Author: User

If object_id (' [TB] ') is not null drop table [TB]
Go
CREATE TABLE [TB] ([SNO] int,[sname] varchar (4), [ssex] varchar (2), [Sbirthday] datetime,[class] int)
Insert [TB]
Select 108, ' Zeng Hua ', ' man ', ' 1905-05-22 00:00:00.000 ', 95033 UNION ALL
Select 105, ' Kuanming ', ' Male ', ' 1905-05-18 00:00:00.000 ', 95031 UNION ALL
Select 107, ' Wang Li ', ' female ', ' 1905-05-07 00:00:00.000 ', 95033 UNION ALL
Select 101, ' Li June ', ' male ', ' 1905-05-09 00:00:00.000 ', 95033 UNION ALL
Select 109, ' Wang Fang ', ' female ', ' 1905-05-18 00:00:00.000 ', 95031 UNION ALL
Select 103, ' Lu Jun ', ' Men ', ' 1905-05-20 00:00:00.000 ', 95031

Start--------------------------------Query------------------------------

SELECT * FROM [TB] where year (sbirthday) = (select year (sbirthday) from TB where [sno]=108)
/*
Sno Sname Ssex Sbirthday Class
----------- ----- ---- ----------------------- -----------
108 Zeng Hua men 1905-05-22 00:00:00.000 95033
105 Kuanming 1905-05-18 00:00:00.000 95031
107 Wang Liju 1905-05-07 00:00:00.000 95033
101 Li Junnan 1905-05-09 00:00:00.000 95033
109 Wang Fang female 1905-05-18 00:00:00.000 95031
103 Lu Junnan 1905-05-20 00:00:00.000 95031

(6 rows affected)


*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.