/* You manage an online event ticketing system where each ticket has a unique Ticket Code in the following format:  
"<priority_code><region_code><ticket_number>"

• `priority_code`: First 3 characters (e.g., "HIG", "MED", "LOW").  
• `region_code`: The next 2 characters (e.g., "NA", "EU", "AP").  
• `ticket_number`: Remaining digits after the region code.  

Input:
| ticket_id | ticket_title                | ticket_code | ticket_status |  
|-----------|-----------------------------|-------------|---------------|  
| 1         | VIP Access Pass Issue       | HIGNA7001   | Open          |  
| 2         | Standard Seat Reservation   | LOWEU4500   | Resolved      |  
| 3         | Premium Seat Upgrade Issue  | HIGAP6502   | Open          |  
| 4         | General Admission Issue     | MEDNA3200   | Closed        |  
| 5         | VIP Parking Pass Not Valid  | HIGEU8005   | Open          |  
| 6         | Ticket Cancellation Problem | LOWNA2001   | Resolved      |  
| 7         | Payment Processing Delay    | MEDAP3400   | Closed        |  
| 8         | Invalid QR Code Scanned     | HIGNA6100   | Resolved      |  

Task:
Write a query using only `LEFT()` and `RIGHT()` to:

1. Extract the priority_code (the first 3 characters).  
2. Extract the region_code (the 4th and 5th characters).  
3. Extract the ticket_number (all remaining digits after the first 5 characters).  
4. Display tickets where:  
   • `priority_code` is "HIG".  
   • `ticket_number` is greater than 6000.  

Expected Output:
| ticket_id | ticket_title                | priority_code | region_code | ticket_number | ticket_status |  
|-----------|-----------------------------|---------------|-------------|---------------|---------------|  
| 1         | VIP Access Pass Issue       | HIG           | NA          | 7001          | Open          |  
| 3         | Premium Seat Upgrade Issue  | HIG           | AP          | 6502          | Open          |  
| 5         | VIP Parking Pass Not Valid  | HIG           | EU          | 8005          | Open          |  
| 8         | Invalid QR Code Scanned     | HIG           | NA          | 6100          | Resolved      |  

*/
CREATE TABLE event_tickets (
    ticket_id INT PRIMARY KEY,
    ticket_title VARCHAR(255),
    ticket_code VARCHAR(50),
    ticket_status VARCHAR(20)
);

INSERT INTO event_tickets (ticket_id, ticket_title, ticket_code, ticket_status) VALUES
(1, 'VIP Access Pass Issue', 'HIGNA7001', 'Open'),
(2, 'Standard Seat Reservation Error', 'LOWEU4500', 'Resolved'),
(3, 'Premium Seat Upgrade Issue', 'HIGAP6502', 'Open'),
(4, 'General Admission Issue', 'MEDNA3200', 'Closed'),
(5, 'VIP Parking Pass Not Valid', 'HIGEU8005', 'Open'),
(6, 'Ticket Cancellation Problem', 'LOWNA2001', 'Resolved'),
(7, 'Payment Processing Delay', 'MEDAP3400', 'Closed'),
(8, 'Invalid QR Code Scanned', 'HIGNA6100', 'Resolved');


SELECT
    ticket_id,
    ticket_title,
    LEFT(ticket_code,3) AS priority_code,
    RIGHT(LEFT(ticket_code,5),2) AS region_code,
    RIGHT(ticket_code,4) AS ticket_number,
    ticket_status
FROM event_tickets
WHERE RIGHT(ticket_code,4) > 6000 AND LEFT(ticket_code,3) = 'HIG';

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: