Простите свернутый пример, но я считаю, что есть что-то фундаментальное в sql, которого я пропускаю, и я не уверен, что это такое. У меня есть этот безумный запрос ...Bubbling Up Columns in Sql
SELECT *
FROM (
SELECT *
FROM (
SELECT @t1 := @t1 +1 AS leaderboard_entry_youngness_rank, 1 - @t1 /100 AS
leaderboard_entry_youngness_based_on_expiry, leaderboard_entry . * ,
NOW() - leaderboard_entry_timestamp AS leaderboard_entry_age_in_some_units,
TO_DAYS(NOW()) - TO_DAYS(leaderboard_entry_timestamp)
AS leaderboard_entry_age_in_days
FROM leaderboard_entry) AS inner_temp
NATURAL JOIN leaderboard
NATURAL JOIN user
WHERE (
leaderboard_load_key = 'sk-en-adjectives-1'
OR leaderboard_load_key = '-sk-en-adjectives-1'
)
AND leaderboard_quiz_mode = '0'
ORDER BY leaderboard_entry_age_in_some_units ASC , leaderboard_entry_timestamp ASC
LIMIT 0 , 100
) AS outer_temp
ORDER BY leaderboard_entry_elapsed_time_ms ASC , leaderboard_entry_timestamp ASC
LIMIT 0 , 50
I added the second nested SELECT statement because the user_name in the user table was not being returned in the outermost query. But now the leaderboard_entry_youngness_based_on_expiry field, which is being generated based on a row index ratio, is not working correctly.
If I remove the second nested SELECT statement, the leaderboard_entry_youngness_based_on_expiry works as expected, but the user_name column is not returned.
How can I satisfy both? Why is this happening?
Thanks!
This stems from the following question:
Add a numbered list column to a returned MySQL query
Откуда появляется столбец 'user_name'? возможно ли это в более чем 1 таблице? –
Столбец user_name исходит из таблицы пользователя, а nope это не в нескольких таблицах :( – swinefeaster
вы не задали для каждой переменной сеанса '@ t1' значение 0 каждый раз перед запуском запроса? –