我有这张桌子
userid fieldid data
1 2 123123
1 3 name
1 4 something
如何为不同别名的fieldid 2和3选择数据?
SELECT data AS nrew FROM inf_data where fieldid ='1'
<<而另一个有不同的别名?
我想得到:
userid nrEw(fieldid=2) smth(fieldid=4)
1 123123 something
答案 0 :(得分:2)
您可以使用加入
select i1.data as nrew, i2.data as smth from inf_data i1 join inf_data i2 on i1.userid=i2.userid where i1.fieldid='1' and i2.fieldid='4'
不确定是否需要“on i1.userid = i2.userid”并且有效,您可以添加另一个where语句:
select i1.data as nrew, i2.data as smth from inf_data i1 join inf_data i2 where i1.fieldid='1' and i2.fieldid='4' and i1.userid='1' and i2.userid='1'
答案 1 :(得分:1)
一种方法使用条件聚合:
alert('Before the Delay');
function afterDelay() {
alert('After the Delay');
}
setTimeout(afterDelay, 2000);