如何在mysql的结果查询中只得到第二行?

时间:2015-11-13 04:47:49

标签: php

enter image description here

在图像结果我的查询mysql。如何使用PHP获得第2行?

2 个答案:

答案 0 :(得分:0)

如果您的意思是2行,请使用

select * from table_name where baris = 2;

如果您只想获取第二行

select * from table_name LIMIT 1, 1;

如果您想使用ORDER BY子句,也可以使用它(仅当您正在寻找2nd largest or 2nd smallest时才这样做。)

答案 1 :(得分:0)

这是我的查询

        SELECT SUM(nilai.nilai) as total, COUNT(nilai.nilai) as baris FROM nilai JOIN data_nilai
         ON nilai.id_data_nilai = data_nilai.idx
            WHERE data_nilai.id_tahun_ajar = '1' 
                AND data_nilai.id_sekolah = '1040902040' 
                AND data_nilai.id_kelas = '2' 
                AND data_nilai.id_rombel = '2' 
                AND data_nilai.id_mapel = '13' 
                AND data_nilai.status_nilai = '0' 
                AND data_nilai.id_jn = '1'
                AND nilai.user_id = 'IDS0000707'
    UNION
    SELECT SUM(nilai.nilai) as total, COUNT(nilai.nilai) as baris FROM nilai JOIN data_nilai
         ON nilai.id_data_nilai = data_nilai.idx
            WHERE data_nilai.id_tahun_ajar = '1' 
                AND data_nilai.id_sekolah = '1040902040' 
                AND data_nilai.id_kelas = '2' 
                AND data_nilai.id_rombel = '2' 
                AND data_nilai.id_mapel = '13' 
                AND data_nilai.status_nilai = '0' 
                AND data_nilai.id_jn = '2'
                AND nilai.user_id = 'IDS0000707'

    UNION
        SELECT SUM(nilai.nilai) as total, COUNT(nilai.nilai) as baris FROM nilai JOIN data_nilai
         ON nilai.id_data_nilai = data_nilai.idx
            WHERE data_nilai.id_tahun_ajar = '1' 
                AND data_nilai.id_sekolah = '1040902040' 
                AND data_nilai.id_kelas = '2' 
                AND data_nilai.id_rombel = '2' 
                AND data_nilai.id_mapel = '13' 
                AND data_nilai.status_nilai = '0' 
                AND data_nilai.id_jn = '3'
                AND nilai.user_id = 'IDS0000707'
    UNION
        SELECT SUM(nilai.nilai) as total, COUNT(nilai.nilai) as baris FROM nilai JOIN data_nilai
         ON nilai.id_data_nilai = data_nilai.idx
            WHERE data_nilai.id_tahun_ajar = '1' 
                AND data_nilai.id_sekolah = '1040902040' 
                AND data_nilai.id_kelas = '2' 
                AND data_nilai.id_rombel = '2' 
                AND data_nilai.id_mapel = '13' 
                AND data_nilai.status_nilai = '0' 
                AND data_nilai.id_jn = '8'
                AND nilai.user_id = 'IDS0000707'