 		hk_nh.HK asc;
 END$$
 
+CREATE DEFINER=`root`@`localhost` PROCEDURE `get_tt_sv_diem_hp_tl`(IN `nk` char(9),IN `hk` tinyint(4),IN `id_sv` int)
+BEGIN
+(SELECT
+		mh.MA_MH,
+		mh.TEN_MH,
+		mh.DIEU_KIEN,
+		hp.MA_HP,
+		mh.SO_TC,
+		ct_hp.DIEM_CHU,
+		ct_hp.DIEM_10,
+		ct_hp.DIEM_4,
+		ct_hp.TL,
+		ct_hp.CAI_THIEN,
+		hk_nh.NK,
+		hk_nh.HK
+	FROM
+		hp
+		INNER JOIN mh ON mh.ID = hp.ID_MH
+		INNER JOIN ct_hp ON hp.ID = ct_hp.ID_HP
+		INNER JOIN hk_nh ON hk_nh.ID = hp.ID_HK_NH
+	WHERE
+		 ct_hp.ID_SV = `id_sv` AND
+		 ct_hp.TL = 1 AND
+		 STRCMP(hk_nh.NK, `nk`) = -1
+) UNION (
+SELECT
+		mh.MA_MH,
+		mh.TEN_MH,
+		mh.DIEU_KIEN,
+		hp.MA_HP,
+		mh.SO_TC,
+		ct_hp.DIEM_CHU,
+		ct_hp.DIEM_10,
+		ct_hp.DIEM_4,
+		ct_hp.TL,
+		ct_hp.CAI_THIEN,
+		hk_nh.NK,
+		hk_nh.HK
+	FROM
+		hp
+		INNER JOIN mh ON mh.ID = hp.ID_MH
+		INNER JOIN ct_hp ON hp.ID = ct_hp.ID_HP
+		INNER JOIN hk_nh ON hk_nh.ID = hp.ID_HK_NH
+	WHERE
+		 ct_hp.ID_SV = `id_sv` AND
+		 ct_hp.TL = 1 AND
+		 hk_nh.NK = `nk` AND
+		 hk_nh.HK <= `hk`  
+);
+END$$
+
 CREATE DEFINER=`root`@`localhost` PROCEDURE `get_tt_sv_login`(IN `id_sv` int)
 BEGIN
 	SELECT sv.MSSV AS 1_MSSV, sv.HO_TEN as 2_HO_TEN, 

		mh.SO_TC,
		ct_hp.DIEM_CHU,
		ct_hp.DIEM_10,
		ct_hp.TL,
		ct_hp.CAI_THIEN,
		hk_nh.NK,

  `ID_MH` int(10) unsigned NOT NULL,
  `ID_HK_NH` int(10) unsigned NOT NULL,
  `ID_GV` int(10) unsigned NOT NULL,
  `MA_HP` varchar(8) COLLATE utf8_bin NOT NULL,
  `LT` tinyint(4) NOT NULL,
  `TH` tinyint(4) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
