显示某个表所有的内容
select * from departments;
输出如下
DEPARTMENT_ID DEPARTMENT_NAME MANAGER_ID LOCATION_ID ------------- ------------------------------------------------------------ ---------- ----------- 10 Administration 200 1700 20 Marketing 201 1800 30 Purchasing 114 1700 40 Human Resources 203 2400 50 Shipping 121 1500 60 IT 103 1400 70 Public Relations 204 2700 80 Sales 145 2500 90 Executive 100 1700 100 Finance 108 1700 110 Accounting 205 1700 120 Treasury 1700 130 Corporate Tax 1700 140 Control And Credit 1700 150 Shareholder Services 1700 160 Benefits 1700 170 Manufacturing 1700 180 Construction 1700 190 Contracting 1700 200 Operations 1700 210 IT Support 1700 220 NOC 1700 230 IT Helpdesk 1700 240 Government Sales 1700 250 Retail Sales 1700 260 Recruiting 1700 270 Payroll 1700 27 rows selected.
备注:如果输出出现了乱码,换行非常频繁,可以输入以下的语句调整单行的显示量
set line 200
数据库select语句显示特定的列
有时候我们不需要显示特别多的行,只需要显示特定的行,我们可以输入以下的指令
select department_id, location_id FROM departments;
这样只会显示两行的信息,我们不需要的信息不会输出
DEPARTMENT_ID LOCATION_ID ------------- ----------- 10 1700 20 1800 30 1700 40 2400 50 1500 60 1400 70 2700 80 2500 90 1700 100 1700 110 1700 120 1700 130 1700 140 1700 150 1700 160 1700 170 1700 180 1700 190 1700 200 1700 210 1700 220 1700 230 1700 240 1700 250 1700 260 1700 270 1700 27 rows selected.
使用算数运算符号
SQL中显示出来的内容,是可以经过运算后输出的,命令如下
SELECT last_name, salary, salary + 300 FROM employees;
我们会产生如下的输出
LAST_NAME SALARY SALARY+300 -------------------------------------------------- ---------- ---------- King 24000 24300 Kochhar 17000 17300 De Haan 17000 17300 Hunold 9000 9300 Ernst 6000 6300 Austin 4800 5100 Pataballa 4800 5100 Lorentz 4200 4500 Greenberg 12000 12300 Faviet 9000 9300 Chen 8200 8500 Sciarra 7700 8000 Urman 7800 8100 Popp 6900 7200 Raphaely 11000 11300 Khoo 3100 3400 Baida 2900 3200 Tobias 2800 3100 Himuro 2600 2900 Colmenares 2500 2800 Weiss 8000 8300 Fripp 8200 8500 Kaufling 7900 8200 Vollman 6500 6800 Mourgos 5800 6100 Nayer 3200 3500 Mikkilineni 2700 3000 Landry 2400 2700 Markle 2200 2500 Bissot 3300 3600 Atkinson 2800 3100 Marlow 2500 2800 Olson 2100 2400 Mallin 3300 3600 Rogers 2900 3200 Gee 2400 2700 Philtanker 2200 2500 Ladwig 3600 3900 Stiles 3200 3500 Seo 2700 3000 Patel 2500 2800 Rajs 3500 3800 Davies 3100 3400 Matos 2600 2900 Vargas 2500 2800 Russell 14000 14300 Partners 13500 13800 LAST_NAME SALARY SALARY+300 -------------------------------------------------- ---------- ---------- Errazuriz 12000 12300 Cambrault 11000 11300 Zlotkey 10500 10800 Tucker 10000 10300 Bernstein 9500 9800 Hall 9000 9300 Olsen 8000 8300 Cambrault 7500 7800 Tuvault 7000 7300 King 10000 10300 Sully 9500 9800 McEwen 9000 9300 Smith 8000 8300 Doran 7500 7800 Sewall 7000 7300 Vishney 10500 10800 Greene 9500 9800 Marvins 7200 7500 Lee 6800 7100 Ande 6400 6700 Banda 6200 6500 Ozer 11500 11800 Bloom 10000 10300 Fox 9600 9900 Smith 7400 7700 Bates 7300 7600 Kumar 6100 6400 Abel 11000 11300 Hutton 8800 9100 Taylor 8600 8900 Livingston 8400 8700 Grant 7000 7300 Johnson 6200 6500 Taylor 3200 3500 Fleaur 3100 3400 Sullivan 2500 2800 Geoni 2800 3100 Sarchand 4200 4500 Bull 4100 4400 Dellinger 3400 3700 Cabrio 3000 3300 Chung 3800 4100 Dilly 3600 3900 Gates 2900 3200 Perkins 2500 2800 Bell 4000 4300 Everett 3900 4200 LAST_NAME SALARY SALARY+300 -------------------------------------------------- ---------- ---------- McCain 3200 3500 Jones 2800 3100 Walsh 3100 3400 Feeney 3000 3300 OConnell 2600 2900 Grant 2600 2900 Whalen 4400 4700 Hartstein 13000 13300 Fay 6000 6300 Mavris 6500 6800 Baer 10000 10300 Higgins 12000 12300 Gietz 8300 8600 107 rows selected.
SQL还支持一些更复杂的运算
SELECT last_name, salary, 12*salary+100 FROM employees;
输出如下
LAST_NAME SALARY 12*SALARY+100 -------------------------------------------------- ---------- ------------- King 24000 288100 Kochhar 17000 204100 De Haan 17000 204100 Hunold 9000 108100 Ernst 6000 72100 Austin 4800 57700 Pataballa 4800 57700 Lorentz 4200 50500 Greenberg 12000 144100 Faviet 9000 108100 Chen 8200 98500 Sciarra 7700 92500 Urman 7800 93700 Popp 6900 82900 Raphaely 11000 132100 Khoo 3100 37300 Baida 2900 34900 Tobias 2800 33700 Himuro 2600 31300 Colmenares 2500 30100 Weiss 8000 96100 Fripp 8200 98500 Kaufling 7900 94900 Vollman 6500 78100 Mourgos 5800 69700 Nayer 3200 38500 Mikkilineni 2700 32500 Landry 2400 28900 Markle 2200 26500 Bissot 3300 39700 Atkinson 2800 33700 Marlow 2500 30100 Olson 2100 25300 Mallin 3300 39700 Rogers 2900 34900 Gee 2400 28900 Philtanker 2200 26500 Ladwig 3600 43300 Stiles 3200 38500 Seo 2700 32500 Patel 2500 30100 Rajs 3500 42100 Davies 3100 37300 Matos 2600 31300 Vargas 2500 30100 Russell 14000 168100 Partners 13500 162100 LAST_NAME SALARY 12*SALARY+100 -------------------------------------------------- ---------- ------------- Errazuriz 12000 144100 Cambrault 11000 132100 Zlotkey 10500 126100 Tucker 10000 120100 Bernstein 9500 114100 Hall 9000 108100 Olsen 8000 96100 Cambrault 7500 90100 Tuvault 7000 84100 King 10000 120100 Sully 9500 114100 McEwen 9000 108100 Smith 8000 96100 Doran 7500 90100 Sewall 7000 84100 Vishney 10500 126100 Greene 9500 114100 Marvins 7200 86500 Lee 6800 81700 Ande 6400 76900 Banda 6200 74500 Ozer 11500 138100 Bloom 10000 120100 Fox 9600 115300 Smith 7400 88900 Bates 7300 87700 Kumar 6100 73300 Abel 11000 132100 Hutton 8800 105700 Taylor 8600 103300 Livingston 8400 100900 Grant 7000 84100 Johnson 6200 74500 Taylor 3200 38500 Fleaur 3100 37300 Sullivan 2500 30100 Geoni 2800 33700 Sarchand 4200 50500 Bull 4100 49300 Dellinger 3400 40900 Cabrio 3000 36100 Chung 3800 45700 Dilly 3600 43300 Gates 2900 34900 Perkins 2500 30100 Bell 4000 48100 Everett 3900 46900 LAST_NAME SALARY 12*SALARY+100 -------------------------------------------------- ---------- ------------- McCain 3200 38500 Jones 2800 33700 Walsh 3100 37300 Feeney 3000 36100 OConnell 2600 31300 Grant 2600 31300 Whalen 4400 52900 Hartstein 13000 156100 Fay 6000 72100 Mavris 6500 78100 Baer 10000 120100 Higgins 12000 144100 Gietz 8300 99700 107 rows selected.
sql
标签:1700,SALARY,3200,练习,3100,堂上,SQL,2800,2500 From: https://www.cnblogs.com/alphainf/p/16725258.html