简体   繁体   中英

How to Get unique data in SQL query?

I have added a my sql query in wordpress function. now i want to get unique data from sql with highest number of "Score".

Ex: This is my SQL Table

I want 2 Results from this table in PHP.

     Quiz_name             Quiz_id        Correct_score   User_ID

     KENNISMAKING          1              0               1
     KENNISMAKING          1              33              1
     KENNISMAKING          1              100             1
     KENNISMAKING          1              33              1
     KENNISMAKING          1              100             1
     KENNISMAKING          1              66              1
     ACTIEF VERKOPEN       7              33              1
     KENNISMAKING          1              12              1
     ASSORTIMENT-FRIS      15             50              1
     ASSORTIMENT-FRIS      15             50              1
     ASSORTIMENT-FRIS      15             25              1
     ASSORTIMENT-FRIS      15             25              1
     ASSORTIMENT-PSV       13             50              1
     ASSORTIMENT-FRIS      15             50              1
     ASSORTIMENT-PSV       13             100             1
     ACTIEF VERKOPEN       7              100             1
     ACTIEF VERKOPEN       7              100             1
     PERSONEELSZAKEN       6              33              1
     ASSORTIMENT-FRIS      15             75              1
  1. Total Number of Unique quiz taken by User 1. (Ex if "KENNISMAKING" appear 7 times so count this only 1).

Output: User 1 Attend Total "5" Quiz (KENNISMAKING, ACTIEF VERKOPEN, ASSORTIMENT-FRIS, ASSORTIMENT-PSV, PERSONEELSZAKEN).

(Note: Only want Number not names.)

  1. Total Count of 100% (Correct_score) taken by user 1. from this Unique Quiz name. (If KENNISMAKING has 2 [100% Correct_score] (See line number 3,5) so count this only 1)

Output: User 1 Complete 3 Quiz 100%.

raw sql. assuming the table name is quiz

  1. SELECT count(distinct(Quiz_name)) FROM quiz WHERE User_ID == 1;
  2. SELECT count(distinct(Quiz_name)) FROM quiz WHERE User_ID == 1 and Correct_score == 100;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM