如何利用SQL语句实现单表、多表查询

如何利用SQL语句实现单表、多表查询,第1张

单表查询可以用如下类似的语法

select col1,col2,col3 from table1 where col1 = 'a'

多表查询的话可能要看你想要实现的结果,有内联接,外联接等写法

如 select a.col1,a.col2,b.col1,b.col2 from a join b where a.col3 = b.col3

select 用户,count(任务) as '任务总数',

count(case 状态='进行' then 状态 end ) as '进行的数量',

count(case 状态='延期' then 状态 end ) as '延期的数量',

count(case 状态='取消' then 状态 end ) as '取消的数量',

count(case 状态='完成' then 状态 end ) as '完成的数量' 

from 表格名 group by 用户

你好

数据库的表查询语句使用的是select语句

格式如下:

select 字段 from 表名 过滤条件;

过滤条件字句:

where 字段=’过滤’;

其中,字句可以写的非常复杂,包括子查询,嵌套子查询等等

学习好一个查询至少要三五天时间

祝你好运

望采纳


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/10715609.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-10
下一篇 2023-05-10

发表评论

登录后才能评论

评论列表(0条)

保存