sql join 的问题

来源:百度知道 编辑:UC知道 时间:2024/05/25 05:58:18
可以把多个select 的结果通过join让它们在一个框里列出来吗
如果可以 麻烦把实现的代码大概的写一下
小弟在这边表示感谢了
就是类似(select * from * where * )join (select * from * where *)这样的可以实现吗 如何实现啊
谢了
就是我要查询总人数、及格人数还有不及格人数 我分别select了 但想让结果像下面这样显示
总人数 及格人数 不及格人数
23 19 4
该怎么弄才好。。。

join就象楼上说的那样,但是看你的意思好像不是join,好像是union
那么首先确定两个表的表结构相同,也就是字段类型都一致
然后select 字段1,字段2 from table1 union all select 字段1,字段2 from table2

字段1和字段2是我自己写的,当然你要确定属性相同后可以选更多的字段,表结构相同的话,可以select *

select a.总人数,b.及格人数,c.不及格人数 from (select count(*) as 总人数 from table) a,(select count(*) as 及格人数 from table where 成绩=及格) b,(select count(*) as 不及格人数 from table where 成绩=不及格) c

mysql中有left join,right join ,cross join等,mysql手册中关于join语法的介绍:
table_references:
table_reference [, table_reference] …

table_reference:
table_factor
| join_table

table_factor:
tbl_name [[AS] alias]
[{USE|IGNORE|FORCE} INDEX (key_list)]
| ( table_references )
| { OJ table_reference LEFT OUTER JOIN table_reference
ON conditional_expr }

join_table:
table_reference [INNER | CROSS] JOIN table_factor [join_condition]
| table_reference STRAIGHT_JOIN table_factor
| tab