大家。我有2张桌子
|tid | t_name | t_desc | max_size |
----------------------------------
|6 | GO TO HELL | DSADA | 13 |
|7 | GO TO das | DSADA | 9 |
|7 | GO TO das | DSADA | 9 |
SELECT count(b.u_id) as counter, a.size as p_size
from trips a
left join lobby b ON b.t_id=6
我需要从大厅中计算u_id,其中t_id = 6(在Trips表中为tid)并显示:count和max_size from(trips) 我的SQL查询如此简单:
function elementStyles(){
var bgcolor = $("input#id_bgcolor").val();
var color = $("input#id_textcolor").val();
var marginbottom = $("input#id_margin_btm").val();
var borderradius = $("input#id_border_rad").val();
$("h2").css({
"background-color": bgcolor,
"color": color
});
$("div").css({
"margin-bottom": marginbottom,
"border-radius": borderradius
});
}
$("input, select").on("change keyup, function(){
elementStyles();
});
但是查询结果显示我没有counter = 1和max_size = 13,这个查询重写了计数器3和max_size 13
答案 0 :(得分:2)
您需要在查询的ON
子句中匹配来自两个表的记录的谓词:
SELECT count(b.u_id) as counter, b.max_size
from trips a
left join lobby b ON a.tid = b.tid
WHERE a.t_id=6
答案 1 :(得分:0)
我不明白为什么你有join
:
SELECT COUNT(*) as counter, MAX(a.size) as p_size
FROM trips t
WHERE t.tid = 6
所有信息都在一个表格中。