Retrieve data from tables

  1. Write a SQL statement to display all the information of all salesmen.
    SELECT * FROM salesman;
  2. Write a SQL statement to display a string “This is SQL Exercise, Practice and Solution”.
    SELECT 'This is SQL Exercise, Practice and Solution;'
  3. Write a query to display three numbers in three columns.
    SELECT 2, 3, 4;
  4. Write a query to display the sum of two numbers 10 and 15 from RDMS sever.
    SELECT 10+15;
  5. Write a query to display the result of an arithmetic expression.
    SELECT 2*3;
  6. Write a SQL statement to display specific columns like name and commission for all the salesmen.
    SELECT name, commission
    FROM salesman;
    
  7. Write a query to display the columns in a specific order like order date, salesman id, order number and purchase amount from for all the orders.
    SELECT ord_date, salesman_id, ord_no, purch_amt
    FROM orders;
    
  8. Write a query which will retrieve the value of salesman id of all salesmen, getting orders from the customers in orders table without any repeats.
    SELECT DISTINCT salesman_id
    FROM orders;
    
  9. Write a SQL statement to display names and city of salesman, who belongs to the city of Paris.
    SELECT name, city
    FROM salesman
    WHERE city='Paris';
    
  10. Write a SQL statement to display all the information for those customers with a grade of 200.
    SELECT *
    FROM customer
    WHERE grade=200;
    
  11. Write a SQL query to display the order number followed by order date and the purchase amount for each order which will be delivered by the salesman who is holding the ID 5001.
    SELECT ord_date, ord_no, purch_amt
    FROM orders
    WHERE salesman_id=5001;
    
  12. Write a SQL query to display the Nobel prizes for 1970.
    SELECT *
    FROM nobel_win
    WHERE YEAR=1970;
    
  13. Write a SQL query to know the winner of the 1971 prize for Literature.
    SELECT WINNER
    FROM nobel_win
    WHERE YEAR=1971
    AND SUBJECT='Literature';
    
  14. Write a SQL query to display the year and subject that won ‘Dennis Gabor’ his prize.
    SELECT YEAR, SUBJECT
    FROM nobel_win
    WHERE WINNER='Dennis Gabor';
    
  15. Write a SQL query to give the name of the ‘Physics’ winners since the year 1950.
    SELECT WINNER
    FROM nobel_win
    WHERE YEAR>=1950
    AND SUBJECT='Physics';
    
  16. Write a SQL query to Show all the details (year, subject, winner, country ) of the Chemistry prize winners between the year 1965 to 1975 inclusive.
    SELECT *
    FROM nobel_win
    WHERE SUBJECT='Chemistry'
    AND YEAR BETWEEN 1965 AND 1975;
    --------
    SELECT *
    FROM nobel_win
    WHERE subject = 'Chemistry'
    AND year>=1965 AND year<=1975;
    
  17. Write a SQL query to show all details of the Prime Ministerial winners after 1972 of Menachem Begin and Yitzhak Rabin.
    SELECT *
    FROM nobel_win
    WHERE YEAR>1972
    AND WINNER in ('Menachem Begin', 'Yitzhak Rabin');
    
  18. Write a SQL query to show all the details of the winners with first name Louis.
    SELECT *
    FROM nobel_win
    WHERE WINNER LIKE 'Louis%';
    
  19. Write a SQL query to show all the winners in Physics for 1970 together with the winner of Economics for 1971.
    SELECT *
    FROM nobel_win
    WHERE (SUBJECT='Physics' AND YEAR=1970)
    OR (SUBJECT='Economics' AND year=1971);
    ------
    SELECT * FROM nobel_win
    WHERE (subject ='Physics' AND year=1970)
    UNION
    SELECT * FROM nobel_win
    WHERE (subject ='Economics' AND year=1971);
    
  20. Write a SQL query to show all the winners of nobel prize in the year 1970 except the subject Physiology and Economics.
    SELECT WINNER
    FROM nobel_win
    WHERE YEAR=1970
    AND SUBJECT NOT IN ('Physiology', 'Economics');
    
  21. Write a SQL query to show the winners of a ‘Physiology’ prize in an early year before 1971 together with winners of a ‘Peace’ prize in a later year on and after the 1974.
    SELECT *
    FROM nobel_win
    WHERE (SUBJECT='Physiology' AND YEAR<1971)
    OR (SUBJECT='Peace' AND YEAR>=1974);
    ------
    SELECT *
    FROM nobel_win
    WHERE (subject ='Physiology' AND year<1971)
    UNION
    SELECT *
    FROM nobel_win
    WHERE (subject ='Peace' AND year>=1974);
    
  22. Write a SQL query to find all details of the prize won by Johannes Georg Bednorz.
    SELECT *
    FROM nobel_win
    WHERE WINNER='Johannes Georg Bednorz';
    
  23. Write a SQL query to find all the details of the nobel winners for the subject not started with the letter ‘P’ and arranged the list as the most recent comes first, then by name in order.
    SELECT *
    FROM nobel_win
    WHERE SUBJECT NOT LIKE 'P%'
    ORDER BY YEAR DESC, WINNER;
    
  24. Write a SQL query to find all the details of 1970 winners by the ordered to subject and winner name; but the list contain the subject Economics and Chemistry at last.
  • 思路:SUBJECT in (‘Economics’, ‘Chemistry’)返回一系列0/1值:如果subject是Economics或Chemistry,则返回1,其余则返回0。使用这一列进行升序排序,即可将 Economics和Chemistry种类的行放在表尾(0<1).

    SELECT *
    FROM nobel_win
    WHERE year=1970
    ORDER BY (SUBJECT in ('Economics', 'Chemistry')), SUBJECT, WINNER
    ------
    SELECT *
    FROM nobel_win
    WHERE year=1970
    ORDER BYCASEWHEN subject IN ('Economics','Chemistry') THEN 1ELSE 0END ASC,subject,winner;
    
  1. Write a SQL query to find all the products with a price between Rs.200 and Rs.600.

    SELECT *
    FROM item_mast
    WHERE PRO_PRICE BETWEEN 200 AND 600;
    
  2. Write a SQL query to calculate the average price of all products of the manufacturer which code is 16.
    SELECT AVG(PRO_PRICE)
    FROM item_mast
    WHERE PRO_COM=16;
    
  3. Write a SQL query to find the item name and price in Rs.
    SELECT pro_name as "Item Name", pro_price AS "Price in Rs."
    FROM item_mast;
    
  4. Write a SQL query to display the name and price of all the items with a price is equal or more than Rs.250, and the list contain the larger price first and then by name in ascending order.
    SELECT PRO_NAME, PRO_PRICE
    FROM item_mast
    WHERE PRO_PRICE>=250
    ORDER BY PRO_PRICE DESC, PRO_NAME;
    
  5. Write a SQL query to display the average price of the items for each company, showing only the company code.
    SELECT AVG(PRO_PRICE), PRO_COM
    FROM item_mast
    GROUP BY PRO_NAME;
    
  6. Write a SQL query to find the name and price of the cheapest item(s).
    SELECT pro_name, pro_price
    FROM item_mast
    WHERE pro_price=(SELECT MIN(pro_price) FROM item_mast);
    
  7. Write a query in SQL to find the last name of all employees, without duplicates.
    SELECT DISTINCT EMP_LNAME
    FROM emp_details;
    
  8. Write a query in SQL to find the data of employees whose last name is ‘Snares’.
    SELECT *
    FROM emp_details
    WHERE EMP_LNAME='Snares';
    
  9. Write a query in SQL to display all the data of employees that work in the department 57.
    SELECT *
    FROM emp_details
    WHERE EMP_DEPT=57;
    

来源:w3resource

SQL-retrieve data from tables相关推荐

  1. Coursera SQL for Data Science - Notes

    SQL for Data Science - Notes 待补充ing 注:同一类编程题型只摘选1~2道做笔记:所有概念题型都不摘选哦,详见课堂讲义 Module 1:Select and Retri ...

  2. Inserting Data Into Tables Using Direct-Path INSERT

    Oracle Database inserts data into a table in one of two ways:(向表中插入数据有两种方法) During conventional INSE ...

  3. java.sql.SQLException: Data truncation: Truncated incorrect DOUBLE value

    mysql 报这个异常:java.sql.SQLException: Data truncation: Truncated incorrect DOUBLE value update 表名 set c ...

  4. SQL Azure(十) SQL Azure Data Sync数据同步功能(上)

    首先举个简单的例子:如果某个大型生产企业包含有2个子系统: - 有一个<产品生产系统>放在企业内部部署,在企业内部办公的员工(生产员工)都可以通过内网来访问该系统.后台的数据库是局域网内的 ...

  5. SQL SERVER data tier application 的作用及如何使用SSDT进行SQL数据库的自动化部署到生产环境和版本控制

    这个是管理员用来发布数据库所有的脚本用的,自SQL2008以后,微软开始将数据库的开发整合到VS2010上,用户可以将数据所有的相关对象打包成一个DAC包,让管理通过extract data-tier ...

  6. 报错:此版本的SQL Server Data Tools与此计算机中安装的数据库运行时组件不兼容...

    在Visual Studio 2012中使用Entity Framework,根据模型生成数据库时,报如下错误: 无法在自定义编辑器中打开Transact-SQL文件 此版本的SQL Server D ...

  7. Using SharePoint 2003 Web Services to Retrieve Data From A List

    Using SharePoint 2003 Web Services to Retrieve Data From A List by Paul Ballard <?xml:namespace p ...

  8. nested exception is java.sql.SQLException: Data truncated for column 'PassWord' at row 72

    tomcat启动没有错误,进入登录界面发现登不进去,出现错误: 2016-08-17 14:52:44 -43568 [http-8080-4] DEBUG   - ==>  Preparing ...

  9. JAVA插入数据库时java.sql.DataTruncation: Data truncation

    今天在做SQL2000的数据库数据交换下,报java.sql.DataTruncation: Data truncation,经过调试 最后才明白.其实就是表的数据结构大小问题   A 表 定义的字段 ...

最新文章

  1. 对装饰器@wraps的解释(一看就懂)-- 并对装饰器详解
  2. libuvc介绍及简单使用
  3. Spring管理Strust的Action
  4. linux socket API / socket
  5. C语言矩阵N*N旋转的算法(附完整源码)
  6. rds基于什么开发_元王RDS--让H公司的10多年的设计经验重获新生!
  7. 简述ajax的优缺点
  8. AcWing 211. 计算系数
  9. 达尔豪西大学 计算机科学,达尔豪西大学计算机科学硕士专业.pdf
  10. java.util.zip.zipexception_Java 压缩zip异常,java.util.zip.ZipException: duplicate entry: 问题...
  11. 感觉养老金越涨差距越大,有人提议高于5000的不再上涨,合理吗?
  12. 非结构化商业文本中隐私信息识别-第2名方案(含数据)
  13. asp.net中时间差的问题
  14. 三笔输入法 开发过程记录
  15. JS表单验证,最详细步骤,代码
  16. 【20180619】【射频通信】混频、中频等高频知识,频谱分析仪的带宽RBW、VBW、SWT,射频信号发生器的使用,GNSS一些基本常识,PCB和MSPS的含义
  17. 什么是受限股票(RSU)、二级市场、蓝筹股
  18. 交替性注意力_注意力不足的小朋友通常都是持续性专注力
  19. 为什么面试官狂问八股文?我已经被三家公司问到哑口无言……
  20. Appscan安全测试

热门文章

  1. Nginx+Docker+Jekyll+阿里云ECS+备案搭建博客全记录
  2. 使用SQL计算AUC值
  3. 计算机组成原理 | 浮点数和定点数(上):怎么用有限的Bit表示尽可能多的信息?...
  4. 推荐给大家一个下载软件的好网站—MSDN I Tell you
  5. Android 之路30---UI基础控件
  6. 女大学生被骗死亡,各国如何应对电话诈骗?
  7. 如何保证游戏长盛不衰
  8. ML:MLOps系列讲解之《设计机器学习驱动的(ML-powered)软件—我们想要解决的业务问题是什么?》解读
  9. 申请邓白氏码(DUNS)步骤
  10. 几个可以免费下载或阅读电子书的网站