I.
Select top 5 ypdm from hospital group by ypdm order by sum (ypsl) DESC
Select top 10 ysdm from hospital where ypdm in (select top 5 ypdm from
Hospital group by ypdm order by sum (ypsl) DESC)
Each time a doctor prescribed a medical treatment, a doctor prescribed a certain amount of medicine. The relationship is as follows:
Doctor workload (ysdm, ypdm, ypsl ).
Ysdm: Doctor code,
Ypdm: drug code,
Ypsl: Number of drugs
Function dependency: (ysdm, ypdm)-> ypsl; Primary Code: (ysdm, ypdm)
SQL statement:
1. The top five drug codes with the largest number of medications;
2. List the top 10 doctors with the largest amount of medication in each of the top five.
Ii. format the date
Select * From convert (varchar (10), getdate (), 112) 20070430
Select * From convert (varchar (10), getdate (), 120)
Select convert (varchar (10), getdate (), 108) 11:23:00
3. Keep the trigger running or stopped at any time as needed?
Alter table trig_example disable trigger trig1
4.
Select a. XX, B. XX from a left join B on A. ID = B. ID where a. ID = 1
Select a. XX, B. XX from a left join B on A. ID = B. ID and A. ID = 1
Select a1.xx, B. XX from (select a. XX from a where a. ID = 1) A1 left join
B On a1.id = B. ID
Which of the above three statements is highly efficient?
5.
Select ps_name, max (time), top 5 tlevel from B left join a on A. ps_id =
B. ps_id order by tlevel DESC
???
6. stored procedures or functions for reading and writing text files
-- Import the Excel table in a directory to the database
-- Put all the Excel files in a directory, assuming C:/test/, and then use the following method
Create Table # T (fname varchar (260), depth int, ISF bit)
Insert into # T exec master .. xp_dirtree 'C:/test', 1, 1
Declare TB cursor for select fn = 'C:/test' + fname from # T
Where ISF = 1 and fname like 'hangzhou.xls '-- .xls file (Excel)
Declare @ FN varchar (8000)
Open TB
Fetch next from TB into @ FN
While @ fetch_status = 0
Begin
-- The following is a query statement. You need to insert the statement as needed.
-- Insert an existing table: insert into Table selct * from...
-- Used to create a table: Select * into table from...
Set @ fn = 'select * from
OpenRowSet (''microsoft. Jet. oledb.4.0 '', ''excel 5.0; HDR = yes; database = '+ @ FN + ''', all customers $ )'
Exec (@ FN)
Fetch next from TB into @ FN
End
Close TB
Deallocate TB
Drop table # T
Importing text files into the database?
The format of the imported text is as follows:
Exec master .. xp_mongoshell 'bcp "dbname .. tablename" in C:/dt.txt-C-sservername-USA-ppassword'