SQL-retrieve data from tables

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情

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 BY
     CASE
        WHEN subject IN ('Economics','Chemistry') THEN 1
        ELSE 0
     END 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

Colab+SQLite+LangChain+Qwen2.5-Coder构建SQL自然语言助手 SQL是关系型数据库的核心操作语言,其语法严谨性与多表关联逻辑常成为数据分析初学者和业务人员的门槛。理解SELECT、JOIN、GROUP BY等基础语句的执行原理,是实现高效数据查询与聚合分析的技术前提。借助大语言模型(LLM)实现Text-to-SQL,可显著降低人工编写SQL的认知负荷,提升分析迭代效率。当前主流方案依赖LangChain框架调度开源代码模型(如Qwen2.5-Coder),结合轻量级SQLite沙盒环境,在免运维的Colab平台上完成端到端验证。该技术路径兼顾准确性、可解释性与工程落 阅读详情

相关推荐

DuckDB实战指南:AI时代的数据加速器与向量分析引擎

DuckDB是一种面向OLAP场景设计的嵌入式列式数据库,其核心优势在于全链路向量化执行、SIMD加速计算和零依赖部署。它通过内存友好的列存结构与原生VECTOR类型,天然支持高效向量相似度计算,成为RAG、NL2SQL等AI数据栈的关键基础设施。相比SQLite的行式事务模型和PostgreSQL的重量级架构,DuckDB在即席分析、本地开发与轻量向量检索中展现出亚秒级响应与极简运维特性。本文聚焦DuckDB在真实AI工程场景中的落地实践,涵盖向量存储构建、NL2SQL查询优化、性能调优及生产部署等关键环

weixin_33874713的博客 400

章鱼搜索破解版(支持在线播放)

章鱼搜索破解版(支持在线播放)

LangChain构建企业级AI智能助手实战指南

大语言模型(LLM)与业务系统的深度集成正在重塑企业智能化转型路径。通过LangChain框架构建的智能助手系统,实现了自然语言到业务工具链的自动路由与执行。核心技术原理涉及意图识别双引擎设计(规则匹配+LLM兜底)、法律检索的语义分块优化、以及NL2SQL的安全防护机制。在金融行业实践中,这类系统能显著提升业务效率,典型应用场景包括智能客服、数据查询分析、法律条文检索等。其中LangGraph的图状态管理实现了复杂工作流编排,而Chroma向量数据库的中文适配特性为本地化部署提供了便利。

weixin_34267123的博客 558

8bit-computer.zip

用数据电路自己设计的8bit计算机,其中包括了时钟,运算器、加法器等硬件电路。

Running SSIS package programmatically

from Michael Entins notebook,thanks for his contribution Running SSIS package programmatically Igot several questions asking what is t

RainyLin-SunnyLin的专栏 3万+

一些收藏

http://blog.csdn.net/zealane/archive/2008/04/28/2339115.aspx http://blog.csdn.net/lauraylin/archive/2008/01/01/2008267.aspx http://lazycn.blog.163.com/blog/static/12883131201011132441439/ 

ssniu1985的专栏 1万+

hdu4565(矩阵快速幂)

A sequence Snis defined as: Where a, b, n, m are positive integers.┌x┐is the ceil of x. For example, ┌3.14┐=4. You are to calculate Sn.   You, a top coder, say: So easy! Input   There a...

qq_40859951的博客 7919

B - Pigeonhole Tower

Pigeon SSNA want to build a tower with some wood walls. Let's describe the tower they want to make: A Tower can consist of different number of level.If a tower contain L levels then 1st level must

yan 7318

【MySQL】一:SQL基础汇总2023(各种单表查询知识点、SQL语句快速参考)

Structured Query Language:结构化查询语言其实就是定义了操作所有关系型数据库的规则。每一种数据库操作的方式存在不一样的地方,称为“方言”。

白骨梦儿 739

SQL:简洁易懂的进阶教程1(views, stored procedures and transactions)

一、views, stored procedures and transactions 1. views 可以从tables, 当前的views选取特定的columns 共同组建新的view 一旦创建完成,view可以像table一样被查询 只有view的定义被存储,相关data不会占用额外的存储空间 使用value的好处: 创建view的命令: CREATE VIEW <view name> (<column_alias_1>, <column_alias_2>

miya的博客 515

c 判断某个类型是否已经定义_SQL:DDL((Data Definition Language)数据定义语言

子曰:“有朋自远方来,不亦乐乎?人不知而不愠,不亦君子乎?” DDL: 用来定义数据库对象:数据库,表,列等。一、操作数据库:CRUD 1、C(Create):创建 CREATE DATABASE DB1; # 创建数据库创建数据库CREATE DATABASE IF NOT EXISTS BD2; #判断是否存在数据库,如果不存在就创建,如果存在也不会报错判断是否存在数据库,如果不存在就创...

weixin_39815879的博客 128

基于大模型与终身记忆构建智能NL2SQL查询系统

自然语言处理(NLP)与数据库查询的结合,正通过大模型技术实现革命性突破。其核心原理是利用预训练语言模型对自然语言语义的深度理解能力,结合代码生成技术,将非结构化的用户需求转化为结构化的查询语言(如SQL)。这一技术的核心价值在于极大降低了数据查询的技术门槛,使业务人员能够直接使用自然语言与数据库交互,从而提升数据驱动决策的效率。在实际应用场景中,通过引入“终身记忆”机制——即持续学习和存储数据库Schema、业务规则及历史查询模式——系统能够像熟悉业务的老手一样精准理解用户意图,并生成准确、安全的SQL

weixin_33744141的博客 322

用 DB15 看清 SAP 归档对象和数据库表之间的关系

SAP数据归档项目的核心挑战在于确定归档对象而非技术操作。归档对象(Archiving Object)是业务导向的,需要处理相关联的多张表而非单表。DB15工具是关键桥梁,可双向查询表与归档对象的映射关系,帮助判断标准归档方案是否适用。但需注意它存在局限,应与AOBJ、SARA等工具配合使用,避免仅凭DB15结果决策。标准归档对象已内置业务逻辑,应优先采用以减少定制化开发风险。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 2121

Text-to-SQL超越人类基准:技术解析与工程实践

自然语言处理领域的重要进展之一,是文本转SQL(Text-to-SQL)技术,它让用户通过自然语言直接生成可执行的SQL查询,大幅降低数据获取门槛。其核心原理是利用大语言模型理解用户意图和数据库结构,并通过“生成-执行-校验”流程提升准确率。随着模型能力不断提升,执行准确率已超过人工标注基准,展现出工业级应用潜力。在BI报表、智能问答、数据分析等场景中,该技术能显著提高取数效率。本文深入解析Text-to-SQL的技术演进、关键设计与工程实践思路,帮助后端开发和数据分析师构建可靠的文本转SQL系统,并规避潜

weixin_30074763的博客 270

智能体式RAG架构设计与金融领域实践

检索增强生成(RAG)技术通过连接大语言模型与外部知识库,有效解决了生成式AI的时效性和准确性问题。其核心原理是将传统检索系统与生成模型结合,先通过语义搜索获取相关知识片段,再基于上下文生成响应。这种架构特别适合需要实时数据支持的场景,如金融分析、医疗咨询等专业领域。随着智能体(Agent)技术的发展,现代RAG系统已进化为具备自主决策能力的智能工作流,能够自动规划查询路径、调用专业工具并验证结果可信度。在金融领域实践中,智能体式RAG可完成从数据采集、多维度分析到可视化呈现的完整链条,典型应用包括上市公司

weixin_30645617的博客 522

Godot-SQLite高性能数据持久化架构设计与实现方案

在游戏开发领域,数据持久化是构建复杂游戏系统的核心技术挑战。传统文件存储方案在多人游戏、跨平台部署和数据一致性方面存在显著局限性。Godot-SQLite作为Godot引擎的原生数据库封装层,通过C++底层实现提供了企业级的SQLite数据库集成方案,为游戏开发者构建高性能、可扩展的数据存储系统提供了架构级解决方案。 [![Godot-SQLite技术架构图](https://raw.gitco

gitblog_01191的博客 325

从零构建智能体:Hermes Agent架构、工具集成与自我改进机制详解

AI智能体(Agent)作为人工智能领域的重要发展方向,正从简单的问答工具演变为能够自主规划、执行复杂任务的智能系统。其核心原理基于大型语言模型的推理能力,结合记忆模块、工具调用机制和规划器,形成“感知-思考-行动”的闭环。在工程实践中,智能体的价值在于将自然语言指令转化为具体的自动化操作,显著提升开发效率和任务执行能力。应用场景广泛覆盖数据分析、自动化办公、智能客服等领域。本文以Hermes Agent为例,深入探讨其架构设计,重点解析如何通过工具(Tools)扩展智能体能力,并实现基于反思机制和向量数据

weixin_30698297的博客 349

MCP:OpenCode上下文语义化的临界点与工程实践

MCP(Model Context Protocol)是一种面向大模型工作流的上下文语义化协议,其核心在于为原始数据注入来源、类型与可信度三类元信息,从而构建可推理的结构化上下文图谱。它不改变模型本身,却显著提升指令理解准确率与跨工具协同稳定性。技术原理上,MCP通过语义隔离(如区分playwright_action与sqlite_ddl)、动态置信度加权和上下文图谱构建,有效缓解传统提示工程中的上下文污染与歧义问题。其技术价值体现在降低错误率、支撑自然语言驱动的数据操作与自动化编排,并已在电商报表、人事系

weixin_34221073的博客 521

LangChain本地实操七日速成:从环境搭建到LangGraph状态机

LangChain作为AI应用编排层,核心价值在于可控、可调试的本地化开发体验。其原理是通过Chain、Agent、Retriever等组件协同调度大模型与工具,实现RAG问答、自然语言查数据库等智能任务。技术价值体现在规避云端黑盒延迟、暴露FAISS硬件适配问题、支持prompt全链路调试等工程优势。典型应用场景包括企业知识库构建、BI数据自然语言查询、智能客服系统开发及学生项目快速验证。本文聚焦本地实操路径,覆盖conda环境隔离、bge-m3中文嵌入、ReAct Agent编排与LangGraph状态

weixin_34074740的博客 360
下一篇: SQL-Boolean and Relational Operators
snistty
博客等级 码龄10年 1粉丝 8原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值