我可以拥有2个表连接结果的别名吗?这样我就可以用别名来调用表的结果。
SELECT emp_table.Name, dept_table.dept
FROM dept_table
inner join emp_table
on emp_table.dept_id = dept_table.dept_id;
答案 0 :(得分:4)
您可以使用子查询:
Track = function (trackId){
var currentTrack = "";
SC.initialize({
client_id: "17a992358db64d99e492326797fff3e8"
});
SC.stream("http://api.soundcloud.com/tracks/" + trackId, function(sound){
currentTrack = sound;
});
this.play = function() {
currentTrack.play();
};
this.pause = function() {
currentTrack.pause();
};
this.stop = function() {
currentTrack.stop();
};
};
Rotation = function(tracks) {
var currentTrack = tracks[0];
this.currentTrack = function () {
return currentTrack;
};
};
$(document).ready (function(){
var songs = [{"soundcloud_id":"108816655"},{"soundcloud_id":"79408289"}]
var rotation = new Rotation(songs);
var currentTrack = rotation.currentTrack();
var currentPlayingTrack = new Track(currentTrack.soundcloud_id);
$('#play').on('click', function(event){
currentPlayingTrack.play();
$('#pause').show();
$('#play').hide();
});
$('#pause').on('click', function(event){
currentPlayingTrack.pause();
$('#pause').hide();
$('#play').show();
});
$('#stop').on('click', function(event){
currentPlayingTrack.stop();
$('#pause').hide();
$('#play').show();
});
});
或使用CTE:
SELECT YourAlias.Name
,YourAlias.dept
FROM (SELECT emp_table.Name, dept_table.dept
FROM dept_table
INNER JOIN emp_table
on emp_table.dept_id = dept_table.dept_id) AS YourAlias;
有关CTE here的更多信息。
答案 1 :(得分:2)
只需输入派生表:
select dt.Name, dt.dept
from
(
SELECT emp_table.Name, dept_table.dept
FROM dept_table
inner join emp_table
on emp_table.dept_id = dept_table.dept_i
) dt;
答案 2 :(得分:1)
不完全但假设列别名和表别名如此
SELECT e.Name as aliasname, d.dept as aliasdept
FROM dept_table d
inner join emp_table e
on e.dept_id = d.dept_id;
答案 3 :(得分:1)
在SQL Server和许多其他DBMS中,您可以将连接查询包装在括号中,并在右括号后添加别名。
select joined.foo
from
(
select a.foo, b.bar
from
table1 a
inner join
table2 b
on a.baz = b.baz
) joined