SQL-retrieve data from tables

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

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

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

相关推荐

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

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

weixin_34267123的博客 558

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

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

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

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

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

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的博客 321

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

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

weixin_30645617的博客 521

中文编码

Python中默认的编码格式是ASCII格式,在没有修改编码格式前无法正确打印汉字,所以在读取中文时会报错。 解决方法:只需要在文件开头加入 # -*-coding: UTF-8 -*-或者 # coding=utf-8就行了 注意:# coding=utf-8的=号两边不要空格 注意:Python3.X 源码文件默认使用utf-8编码,所以可以正常解析中文,无需指定utf-8编码。 注意:如果你使用编辑器,同时需要设置py文件存储的格式为UTF-8,否则会出现类似以下错误: ...

lisnis的专栏 6304

signature=ada6640b4b5c9f5a7a3dc2c4ac92d154,luban-h5/yarn.lock at master · binball72956/luban-h5 · Gi...

# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.# yarn lockfile v1"@babel/code-frame@^7.0.0":version "7.10.4"resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.10....

weixin_39612849的博客 4万+

20230507使用python3批量转换DOCX文档为TXT

print('共计%d篇docx文章已完全转换为txt' % (pdf_num-1))print('共计%d篇docx文章已完全转换为txt' pdf_num-1))0 个目录 195,912,142,848 可用字节。0 个目录 195,912,142,848 可用字节。

南岭笑笑生之家 1万+

20230508在Ubuntu22.04下使用python3批量转换DOCX文档为TXT

rwxr--r-- 1 rootroot rootroot 80786 5月 4 20:56 MIDE-599.google.docx*-rwxr--r-- 1 rootroot rootroot 1245 5月 7 20:07 'pdf2doc2 - 副本.py'*-rwxr--r-- 1 rootroot rootroot 1245 5月 7 20:07 pdf2doc2.py*python bytes和str两种类型可以通过函数encode()和decode()相互转换,

南岭笑笑生之家 2万+

HDU4565 So Easy! (矩阵)

HDU4565 So easy (矩阵+推公式)

追梦赤子心 2524
下一篇: SQL-Boolean and Relational Operators
snistty
博客等级 码龄10年 1粉丝 8原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值