File size: 163,091 Bytes
606ac8d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 | question,sql,schema_context,domain,difficulty,query_type
List all customers from Germany.,SELECT * FROM customers WHERE country = 'Germany';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
Show the names and emails of all customers.,"SELECT name, email FROM customers;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
Find all orders with status 'pending'.,SELECT * FROM orders WHERE status = 'pending';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
Get the top 10 most expensive products.,SELECT * FROM products ORDER BY price DESC LIMIT 10;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
List products with stock quantity below 20.,"SELECT name, stock_quantity FROM products WHERE stock_quantity < 20;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
Show all orders placed in 2024.,SELECT * FROM orders WHERE order_date >= '2024-01-01' AND order_date < '2025-01-01';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
Find customers who spent more than 1000 in total.,SELECT * FROM customers WHERE total_spent > 1000;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
List all product categories.,SELECT DISTINCT category FROM products;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
Get all suppliers from the United States.,SELECT * FROM suppliers WHERE country = 'United States';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
Find all cancelled orders.,SELECT * FROM orders WHERE status = 'cancelled';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
List all patients from New York.,SELECT * FROM patients WHERE city = 'New York';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
Show all doctors with specialty 'Cardiology'.,SELECT * FROM doctors WHERE specialty = 'Cardiology';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
Find all appointments scheduled for today.,SELECT * FROM appointments WHERE appointment_date = CURRENT_DATE;," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
List hospitals with a rating above 4.,SELECT * FROM hospitals WHERE rating > 4;," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
Get all female patients.,SELECT * FROM patients WHERE gender = 'F';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
Find all confirmed appointments.,SELECT * FROM appointments WHERE status = 'confirmed';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
List prescriptions with duration longer than 30 days.,SELECT * FROM prescriptions WHERE duration_days > 30;," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
Show all doctors with more than 10 years of experience.,SELECT * FROM doctors WHERE years_experience > 10;," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
Find all active users.,SELECT * FROM users WHERE is_active = TRUE;," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,select
List all users on the 'pro' plan.,SELECT * FROM users WHERE plan = 'pro';," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,select
Show all page view events.,SELECT * FROM events WHERE event_type = 'page_view';," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,select
"Find users who signed up after January 1, 2023.",SELECT * FROM users WHERE signup_date > '2023-01-01';," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,select
Get sessions that lasted more than 10 minutes.,SELECT * FROM events WHERE duration_seconds > 600;," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,select
List all employees in the Engineering department.,SELECT e.* FROM employees e JOIN departments d ON e.department_id = d.department_id WHERE d.name = 'Engineering';," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,select
Find employees with salary above 80000.,SELECT * FROM employees WHERE salary > 80000;," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,select
List all employees hired in 2022.,SELECT * FROM employees WHERE hire_date >= '2022-01-01' AND hire_date < '2023-01-01';," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,select
Show all projects with a budget over 500000.,SELECT * FROM projects WHERE budget > 500000;," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,select
Find employees who received a performance rating of 5.,SELECT e.name FROM employees e JOIN performance_reviews pr ON e.employee_id = pr.employee_id WHERE pr.rating = 5;," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,select
List all items with quantity below the reorder point.,"SELECT i.name, i.reorder_point, s.quantity FROM items i JOIN stock s ON i.item_id = s.item_id WHERE s.quantity < i.reorder_point;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,select
Find all warehouses in the United States.,SELECT * FROM warehouses WHERE country = 'United States';," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,select
Show all stock movements of type 'receipt' from last month.,"SELECT * FROM movements WHERE movement_type = 'receipt' AND movement_date >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1 month');"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,select
How many customers are there in total?,SELECT COUNT(*) AS total_customers FROM customers;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the total revenue from all orders?,SELECT SUM(total_amount) AS total_revenue FROM orders;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the average product price?,SELECT AVG(price) AS avg_price FROM products;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the most expensive product price?,SELECT MAX(price) AS max_price FROM products;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many orders are in 'shipped' status?,SELECT COUNT(*) AS shipped_count FROM orders WHERE status = 'shipped';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the average salary of all employees?,SELECT AVG(salary) AS avg_salary FROM employees;," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,aggregate
How many hospitals have more than 200 beds?,SELECT COUNT(*) FROM hospitals WHERE beds > 200;," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
What is the total quantity of all items in stock?,SELECT SUM(quantity) AS total_stock FROM stock;," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,aggregate
How many distinct event types are there?,SELECT COUNT(DISTINCT event_type) AS event_type_count FROM events;," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
What is the minimum salary in the company?,SELECT MIN(salary) AS min_salary FROM employees;," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,aggregate
List all orders along with the customer name and email.,"SELECT o.order_id, c.name, c.email, o.order_date, o.total_amount
FROM orders o
JOIN customers c ON o.customer_id = c.customer_id;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
Show each order item with product name and unit price.,"SELECT oi.item_id, p.name AS product_name, oi.quantity, oi.unit_price
FROM order_items oi
JOIN products p ON oi.product_id = p.product_id;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
Find all orders placed by customers from France.,"SELECT o.*
FROM orders o
JOIN customers c ON o.customer_id = c.customer_id
WHERE c.country = 'France';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
List each product with its supplier name and supplier country.,"SELECT p.name AS product_name, s.name AS supplier_name, s.country
FROM products p
JOIN suppliers s ON p.supplier_id = s.supplier_id;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
"Show all appointments with patient name, doctor name, and diagnosis.","SELECT a.appointment_id, p.name AS patient_name, d.name AS doctor_name,
a.appointment_date, a.diagnosis
FROM appointments a
JOIN patients p ON a.patient_id = p.patient_id
JOIN doctors d ON a.doctor_id = d.doctor_id;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
List each doctor along with the hospital name and city they work in.,"SELECT d.name AS doctor_name, d.specialty, h.name AS hospital_name, h.city
FROM doctors d
JOIN hospitals h ON d.hospital_id = h.hospital_id;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
Find all prescriptions for patients diagnosed with 'Hypertension'.,"SELECT pr.*, p.name AS patient_name
FROM prescriptions pr
JOIN appointments a ON pr.appointment_id = a.appointment_id
JOIN patients p ON a.patient_id = p.patient_id
WHERE a.diagnosis = 'Hypertension';"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
List each employee with their department name and location.,"SELECT e.name, e.salary, d.name AS department_name, d.location
FROM employees e
JOIN departments d ON e.department_id = d.department_id;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,join
"Show all employees assigned to a project, with the project name and their role.","SELECT e.name AS employee_name, p.name AS project_name, a.role, a.hours_per_week
FROM assignments a
JOIN employees e ON a.employee_id = e.employee_id
JOIN projects p ON a.project_id = p.project_id;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,join
"Find all user sessions that lasted more than 30 minutes, with the username.","SELECT u.username, s.session_id, s.start_time, s.end_time, s.device
FROM sessions s
JOIN users u ON s.user_id = u.user_id
WHERE EXTRACT(EPOCH FROM (s.end_time - s.start_time)) > 1800;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,join
List all events with the username and the session device.,"SELECT e.event_id, u.username, e.event_type, e.event_date, s.device
FROM events e
JOIN users u ON e.user_id = u.user_id
JOIN sessions s ON e.session_id = s.session_id;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,join
List each item in stock with its warehouse name and city.,"SELECT i.name AS item_name, i.sku, w.name AS warehouse_name, w.city, s.quantity
FROM stock s
JOIN items i ON s.item_id = i.item_id
JOIN warehouses w ON s.warehouse_id = w.warehouse_id;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,join
Find all receipt movements with the item name and warehouse name.,"SELECT m.movement_id, i.name AS item_name, w.name AS warehouse_name,
m.quantity, m.movement_date
FROM movements m
JOIN items i ON m.item_id = i.item_id
JOIN warehouses w ON m.warehouse_id = w.warehouse_id
WHERE m.movement_type = 'receipt';"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,join
How many orders does each customer have?,"SELECT customer_id, COUNT(*) AS order_count
FROM orders
GROUP BY customer_id
ORDER BY order_count DESC;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
What is the total revenue per product category?,"SELECT p.category, SUM(oi.quantity * oi.unit_price) AS category_revenue
FROM order_items oi
JOIN products p ON oi.product_id = p.product_id
GROUP BY p.category
ORDER BY category_revenue DESC;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
How many products are in each category?,"SELECT category, COUNT(*) AS product_count
FROM products
GROUP BY category
ORDER BY product_count DESC;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
What is the average order value per customer country?,"SELECT c.country, AVG(o.total_amount) AS avg_order_value
FROM orders o
JOIN customers c ON o.customer_id = c.customer_id
GROUP BY c.country
ORDER BY avg_order_value DESC;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
How many appointments does each doctor have?,"SELECT doctor_id, COUNT(*) AS appointment_count
FROM appointments
GROUP BY doctor_id
ORDER BY appointment_count DESC;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,aggregate
What is the average number of beds per city?,"SELECT city, AVG(beds) AS avg_beds
FROM hospitals
GROUP BY city
ORDER BY avg_beds DESC;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,aggregate
"How many patients does each hospital serve, by doctor specialty?","SELECT h.name AS hospital_name, d.specialty, COUNT(DISTINCT a.patient_id) AS patient_count
FROM appointments a
JOIN doctors d ON a.doctor_id = d.doctor_id
JOIN hospitals h ON d.hospital_id = h.hospital_id
GROUP BY h.name, d.specialty
ORDER BY patient_count DESC;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,aggregate
What is the average salary by department?,"SELECT d.name AS department_name, AVG(e.salary) AS avg_salary
FROM employees e
JOIN departments d ON e.department_id = d.department_id
GROUP BY d.name
ORDER BY avg_salary DESC;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,aggregate
How many employees are in each department?,"SELECT d.name AS department, COUNT(e.employee_id) AS employee_count
FROM employees e
JOIN departments d ON e.department_id = d.department_id
GROUP BY d.name
ORDER BY employee_count DESC;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,aggregate
What is the total number of events per event type?,"SELECT event_type, COUNT(*) AS event_count
FROM events
GROUP BY event_type
ORDER BY event_count DESC;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,aggregate
How many users signed up per month in 2023?,"SELECT DATE_TRUNC('month', signup_date) AS month, COUNT(*) AS signups
FROM users
WHERE signup_date >= '2023-01-01' AND signup_date < '2024-01-01'
GROUP BY month
ORDER BY month;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,aggregate
What is the total stock quantity per warehouse?,"SELECT w.name AS warehouse_name, SUM(s.quantity) AS total_quantity
FROM stock s
JOIN warehouses w ON s.warehouse_id = w.warehouse_id
GROUP BY w.name
ORDER BY total_quantity DESC;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,aggregate
How many shipments were received per item last quarter?,"SELECT i.name AS item_name, SUM(m.quantity) AS received
FROM movements m
JOIN items i ON m.item_id = i.item_id
WHERE m.movement_type = 'receipt'
AND m.movement_date >= DATE_TRUNC('quarter', CURRENT_DATE - INTERVAL '3 months')
AND m.movement_date < DATE_TRUNC('quarter', CURRENT_DATE)
GROUP BY i.name
ORDER BY received DESC;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,aggregate
Find customers who have placed more than 5 orders.,"SELECT customer_id, COUNT(*) AS order_count
FROM orders
GROUP BY customer_id
HAVING COUNT(*) > 5
ORDER BY order_count DESC;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
Which product categories have average price above 100?,"SELECT category, AVG(price) AS avg_price
FROM products
GROUP BY category
HAVING AVG(price) > 100
ORDER BY avg_price DESC;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
Find departments where average employee salary is above 75000.,"SELECT d.name, AVG(e.salary) AS avg_salary
FROM employees e
JOIN departments d ON e.department_id = d.department_id
GROUP BY d.name
HAVING AVG(e.salary) > 75000
ORDER BY avg_salary DESC;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,aggregate
Which hospitals have more than 100 appointments in total?,"SELECT h.name, COUNT(a.appointment_id) AS total_appointments
FROM appointments a
JOIN doctors d ON a.doctor_id = d.doctor_id
JOIN hospitals h ON d.hospital_id = h.hospital_id
GROUP BY h.name
HAVING COUNT(a.appointment_id) > 100
ORDER BY total_appointments DESC;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,aggregate
Find users who triggered more than 50 events.,"SELECT user_id, COUNT(*) AS event_count
FROM events
GROUP BY user_id
HAVING COUNT(*) > 50
ORDER BY event_count DESC;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,aggregate
Which items have been restocked more than 10 times?,"SELECT i.name, COUNT(m.movement_id) AS restock_count
FROM movements m
JOIN items i ON m.item_id = i.item_id
WHERE m.movement_type = 'receipt'
GROUP BY i.name
HAVING COUNT(m.movement_id) > 10
ORDER BY restock_count DESC;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,aggregate
Find customers who have never placed an order.,"SELECT * FROM customers
WHERE customer_id NOT IN (SELECT DISTINCT customer_id FROM orders);"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,subquery
Find the product with the highest total quantity sold.,"SELECT p.name, total_sold
FROM products p
JOIN (
SELECT product_id, SUM(quantity) AS total_sold
FROM order_items
GROUP BY product_id
) s ON p.product_id = s.product_id
ORDER BY total_sold DESC
LIMIT 1;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,subquery
List customers whose total spending is above the average total spending.,"SELECT name, total_spent
FROM customers
WHERE total_spent > (SELECT AVG(total_spent) FROM customers)
ORDER BY total_spent DESC;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,subquery
Find products that have never been ordered.,"SELECT * FROM products
WHERE product_id NOT IN (SELECT DISTINCT product_id FROM order_items);"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,subquery
Find the top 3 customers by total order value in 2024.,"SELECT c.name, SUM(o.total_amount) AS total_value
FROM orders o
JOIN customers c ON o.customer_id = c.customer_id
WHERE o.order_date >= '2024-01-01' AND o.order_date < '2025-01-01'
GROUP BY c.name
ORDER BY total_value DESC
LIMIT 3;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,subquery
Find patients who have been prescribed more medications than average.,"SELECT p.name, COUNT(pr.prescription_id) AS prescription_count
FROM patients p
JOIN appointments a ON p.patient_id = a.patient_id
JOIN prescriptions pr ON a.appointment_id = pr.appointment_id
GROUP BY p.patient_id, p.name
HAVING COUNT(pr.prescription_id) > (
SELECT AVG(pcount) FROM (
SELECT COUNT(pr2.prescription_id) AS pcount
FROM appointments a2
JOIN prescriptions pr2 ON a2.appointment_id = pr2.appointment_id
GROUP BY a2.patient_id
) sub
);"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,subquery
Find doctors who have no appointments in the past 6 months.,"SELECT * FROM doctors
WHERE doctor_id NOT IN (
SELECT DISTINCT doctor_id FROM appointments
WHERE appointment_date >= CURRENT_DATE - INTERVAL '6 months'
);"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,subquery
Find employees earning more than the average salary in their own department.,"SELECT e.name, e.salary, d.name AS department
FROM employees e
JOIN departments d ON e.department_id = d.department_id
WHERE e.salary > (
SELECT AVG(e2.salary)
FROM employees e2
WHERE e2.department_id = e.department_id
)
ORDER BY d.name, e.salary DESC;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,hard,subquery
Find the department with the highest total bonus payout.,"SELECT d.name, SUM(pr.bonus) AS total_bonus
FROM performance_reviews pr
JOIN employees e ON pr.employee_id = e.employee_id
JOIN departments d ON e.department_id = d.department_id
GROUP BY d.name
ORDER BY total_bonus DESC
LIMIT 1;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,hard,subquery
Find users who converted but never triggered a 'purchase' event.,"SELECT DISTINCT u.user_id, u.username
FROM conversions c
JOIN users u ON c.user_id = u.user_id
WHERE u.user_id NOT IN (
SELECT user_id FROM events WHERE event_type = 'purchase'
);"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,subquery
Find the page with the highest average session duration.,"SELECT page, AVG(duration_seconds) AS avg_duration
FROM events
GROUP BY page
ORDER BY avg_duration DESC
LIMIT 1;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,subquery
Find items that are stocked in every warehouse.,"SELECT i.name
FROM items i
WHERE NOT EXISTS (
SELECT 1 FROM warehouses w
WHERE NOT EXISTS (
SELECT 1 FROM stock s
WHERE s.item_id = i.item_id AND s.warehouse_id = w.warehouse_id
)
);"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,hard,subquery
"Using a CTE, find the monthly revenue trend for 2024.","WITH monthly_revenue AS (
SELECT DATE_TRUNC('month', order_date) AS month,
SUM(total_amount) AS revenue
FROM orders
WHERE order_date >= '2024-01-01' AND order_date < '2025-01-01'
GROUP BY month
)
SELECT month, revenue,
revenue - LAG(revenue) OVER (ORDER BY month) AS month_over_month_change
FROM monthly_revenue
ORDER BY month;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,cte
"Using a CTE, rank customers by total spending and show the top 5.","WITH customer_spending AS (
SELECT c.customer_id, c.name,
SUM(o.total_amount) AS total_spending
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
GROUP BY c.customer_id, c.name
)
SELECT name, total_spending,
RANK() OVER (ORDER BY total_spending DESC) AS spending_rank
FROM customer_spending
ORDER BY spending_rank
LIMIT 5;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,cte
"Using a CTE, find each department's headcount and its share of total company headcount.","WITH dept_counts AS (
SELECT department_id, COUNT(*) AS headcount
FROM employees
GROUP BY department_id
),
total AS (
SELECT SUM(headcount) AS company_total FROM dept_counts
)
SELECT d.name, dc.headcount,
ROUND(100.0 * dc.headcount / t.company_total, 2) AS pct_of_company
FROM dept_counts dc
JOIN departments d ON dc.department_id = d.department_id
CROSS JOIN total t
ORDER BY dc.headcount DESC;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,hard,cte
"Using a CTE, identify patients with more than 3 appointments and list their diagnoses.","WITH frequent_patients AS (
SELECT patient_id, COUNT(*) AS visit_count
FROM appointments
GROUP BY patient_id
HAVING COUNT(*) > 3
)
SELECT p.name, a.appointment_date, a.diagnosis
FROM appointments a
JOIN patients p ON a.patient_id = p.patient_id
WHERE a.patient_id IN (SELECT patient_id FROM frequent_patients)
ORDER BY p.name, a.appointment_date;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,cte
"Using a CTE, find users who converted within 7 days of signup.","WITH conversion_lag AS (
SELECT u.user_id, u.username, u.signup_date,
MIN(c.event_date) AS first_conversion
FROM users u
JOIN conversions c ON u.user_id = c.user_id
GROUP BY u.user_id, u.username, u.signup_date
)
SELECT username, signup_date, first_conversion,
first_conversion - signup_date AS days_to_convert
FROM conversion_lag
WHERE first_conversion - signup_date <= 7
ORDER BY days_to_convert;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,cte
"Using a CTE, find which warehouses hold items below their reorder point and flag urgency.","WITH low_stock AS (
SELECT s.warehouse_id, s.item_id, s.quantity,
i.reorder_point, i.name AS item_name,
i.reorder_point - s.quantity AS deficit
FROM stock s
JOIN items i ON s.item_id = i.item_id
WHERE s.quantity < i.reorder_point
)
SELECT w.name AS warehouse, ls.item_name, ls.quantity, ls.reorder_point, ls.deficit,
CASE WHEN ls.deficit > ls.reorder_point * 0.5 THEN 'CRITICAL' ELSE 'LOW' END AS urgency
FROM low_stock ls
JOIN warehouses w ON ls.warehouse_id = w.warehouse_id
ORDER BY ls.deficit DESC;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,hard,cte
Rank products by price within each category using a window function.,"SELECT name, category, price,
RANK() OVER (PARTITION BY category ORDER BY price DESC) AS price_rank
FROM products;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,window
"Calculate a running total of order revenue per customer, ordered by date.","SELECT customer_id, order_date, total_amount,
SUM(total_amount) OVER (PARTITION BY customer_id ORDER BY order_date) AS running_total
FROM orders;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,window
Show each employee's salary and how it compares to the department average.,"SELECT name, salary, department_id,
AVG(salary) OVER (PARTITION BY department_id) AS dept_avg,
salary - AVG(salary) OVER (PARTITION BY department_id) AS diff_from_avg
FROM employees;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,hard,window
Rank doctors by appointment count per specialty using DENSE_RANK.,"SELECT d.name, d.specialty,
COUNT(a.appointment_id) AS appt_count,
DENSE_RANK() OVER (PARTITION BY d.specialty ORDER BY COUNT(a.appointment_id) DESC) AS rank_in_specialty
FROM doctors d
LEFT JOIN appointments a ON d.doctor_id = a.doctor_id
GROUP BY d.doctor_id, d.name, d.specialty;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,window
Show each user's cumulative revenue from conversions over time.,"SELECT user_id, event_date, revenue,
SUM(revenue) OVER (PARTITION BY user_id ORDER BY event_date) AS cumulative_revenue
FROM conversions;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,window
"For each event, show the previous event type for the same user.","SELECT user_id, event_date, event_type,
LAG(event_type) OVER (PARTITION BY user_id ORDER BY event_date) AS prev_event_type
FROM events;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,window
Show each item's movement quantity and its percentage of total movements for that item.,"SELECT item_id, movement_date, quantity,
ROUND(100.0 * quantity / SUM(quantity) OVER (PARTITION BY item_id), 2) AS pct_of_item_total
FROM movements
WHERE movement_type = 'receipt'
ORDER BY item_id, movement_date;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,hard,window
Find the second highest salary in each department.,"SELECT department_id, name, salary
FROM (
SELECT department_id, name, salary,
DENSE_RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS rnk
FROM employees
) ranked
WHERE rnk = 2;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,hard,window
"List all customers and their total number of orders, including customers with no orders.","SELECT c.name, COUNT(o.order_id) AS order_count
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id
GROUP BY c.customer_id, c.name
ORDER BY order_count DESC;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
"List all doctors and the number of patients they have seen, including doctors with no appointments.","SELECT d.name, COUNT(a.appointment_id) AS patient_count
FROM doctors d
LEFT JOIN appointments a ON d.doctor_id = a.doctor_id
GROUP BY d.doctor_id, d.name
ORDER BY patient_count DESC;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
"Show all projects and the number of employees assigned, including unassigned projects.","SELECT p.name, COUNT(a.employee_id) AS assigned_employees
FROM projects p
LEFT JOIN assignments a ON p.project_id = a.project_id
GROUP BY p.project_id, p.name
ORDER BY assigned_employees DESC;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,join
How many orders were placed each day of the week on average?,"SELECT EXTRACT(DOW FROM order_date) AS day_of_week,
COUNT(*) / COUNT(DISTINCT DATE_TRUNC('week', order_date)) AS avg_orders_per_week
FROM orders
GROUP BY day_of_week
ORDER BY day_of_week;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
What is the average time between a patient's first and most recent appointment?,"SELECT patient_id,
MIN(appointment_date) AS first_visit,
MAX(appointment_date) AS last_visit,
MAX(appointment_date) - MIN(appointment_date) AS days_span
FROM appointments
GROUP BY patient_id
HAVING COUNT(*) > 1
ORDER BY days_span DESC;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,aggregate
How many new users signed up per week in the last 90 days?,"SELECT DATE_TRUNC('week', signup_date) AS week_start, COUNT(*) AS signups
FROM users
WHERE signup_date >= CURRENT_DATE - INTERVAL '90 days'
GROUP BY week_start
ORDER BY week_start;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,aggregate
Find all products whose name starts with 'Pro'.,SELECT * FROM products WHERE name LIKE 'Pro%';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
Find all customers whose email domain is 'gmail.com'.,SELECT * FROM customers WHERE email LIKE '%@gmail.com';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
Find all patients whose name contains 'John'.,SELECT * FROM patients WHERE name ILIKE '%john%';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
"Categorize orders as 'small', 'medium', or 'large' based on total amount.","SELECT order_id, total_amount,
CASE
WHEN total_amount < 50 THEN 'small'
WHEN total_amount < 200 THEN 'medium'
ELSE 'large'
END AS order_size
FROM orders;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,select
"Classify employees as 'junior', 'mid-level', or 'senior' based on salary.","SELECT name, salary,
CASE
WHEN salary < 50000 THEN 'junior'
WHEN salary < 100000 THEN 'mid-level'
ELSE 'senior'
END AS seniority_level
FROM employees;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,select
"Flag inventory items as 'out of stock', 'low', or 'sufficient'.","SELECT i.name, s.quantity, i.reorder_point,
CASE
WHEN s.quantity = 0 THEN 'out_of_stock'
WHEN s.quantity < i.reorder_point THEN 'low'
ELSE 'sufficient'
END AS stock_status
FROM stock s
JOIN items i ON s.item_id = i.item_id;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,select
What percentage of total revenue does each customer represent?,"SELECT c.name,
SUM(o.total_amount) AS customer_revenue,
ROUND(100.0 * SUM(o.total_amount) / (SELECT SUM(total_amount) FROM orders), 2) AS pct_of_total
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
GROUP BY c.name
ORDER BY customer_revenue DESC;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,subquery
Find the specialty with the highest average patient age.,"SELECT d.specialty, AVG(EXTRACT(YEAR FROM AGE(p.date_of_birth))) AS avg_patient_age
FROM appointments a
JOIN doctors d ON a.doctor_id = d.doctor_id
JOIN patients p ON a.patient_id = p.patient_id
GROUP BY d.specialty
ORDER BY avg_patient_age DESC
LIMIT 1;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,aggregate
Which campaigns had the highest ROI (revenue per conversion)?,"SELECT campaign_id,
COUNT(*) AS conversions,
SUM(revenue) AS total_revenue,
AVG(revenue) AS avg_revenue_per_conversion
FROM conversions
GROUP BY campaign_id
ORDER BY avg_revenue_per_conversion DESC;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,aggregate
Find employees who are assigned to more than 2 active projects.,"SELECT e.name, COUNT(DISTINCT a.project_id) AS project_count
FROM employees e
JOIN assignments a ON e.employee_id = a.employee_id
JOIN projects p ON a.project_id = p.project_id
WHERE p.end_date >= CURRENT_DATE
GROUP BY e.employee_id, e.name
HAVING COUNT(DISTINCT a.project_id) > 2
ORDER BY project_count DESC;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,hard,subquery
Which item SKU has the highest total outbound movement in the last 30 days?,"SELECT i.sku, i.name, SUM(m.quantity) AS outbound_qty
FROM movements m
JOIN items i ON m.item_id = i.item_id
WHERE m.movement_type = 'shipment'
AND m.movement_date >= CURRENT_DATE - INTERVAL '30 days'
GROUP BY i.sku, i.name
ORDER BY outbound_qty DESC
LIMIT 1;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,hard,aggregate
Find all employees and their manager's name.,"SELECT e.name AS employee, m.name AS manager
FROM employees e
LEFT JOIN employees m ON e.manager_id = m.employee_id
ORDER BY m.name NULLS LAST, e.name;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,join
Find pairs of employees in the same department who earn within 5000 of each other.,"SELECT a.name AS employee1, b.name AS employee2, a.salary AS sal1, b.salary AS sal2
FROM employees a
JOIN employees b ON a.department_id = b.department_id
AND a.employee_id < b.employee_id
AND ABS(a.salary - b.salary) <= 5000
ORDER BY a.name;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,hard,join
Find customers who have ordered every product in the 'Electronics' category.,"SELECT c.name
FROM customers c
WHERE NOT EXISTS (
SELECT 1 FROM products p
WHERE p.category = 'Electronics'
AND NOT EXISTS (
SELECT 1 FROM orders o
JOIN order_items oi ON o.order_id = oi.order_id
WHERE o.customer_id = c.customer_id
AND oi.product_id = p.product_id
)
);"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,subquery
Find patients who have seen at least one doctor in every specialty at the hospital.,"SELECT p.name
FROM patients p
WHERE NOT EXISTS (
SELECT 1 FROM doctors d
WHERE NOT EXISTS (
SELECT 1 FROM appointments a
WHERE a.patient_id = p.patient_id AND a.doctor_id = d.doctor_id
)
);"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,subquery
Insert a new customer record.,"INSERT INTO customers (name, email, city, country, created_at, total_spent)
VALUES ('Alice Johnson', 'alice@example.com', 'London', 'United Kingdom', CURRENT_DATE, 0);"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
Update the status of all orders older than 30 days that are still 'pending' to 'cancelled'.,"UPDATE orders
SET status = 'cancelled'
WHERE status = 'pending'
AND order_date < CURRENT_DATE - INTERVAL '30 days';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,select
Delete all sessions that ended more than one year ago.,"DELETE FROM sessions
WHERE end_time < NOW() - INTERVAL '1 year';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,select
How many customers are from Germany?,SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'Germany';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many customers are from France?,SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'France';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many customers are from United Kingdom?,SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'United Kingdom';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many customers are from Canada?,SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'Canada';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many customers are from Australia?,SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'Australia';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many customers are from Japan?,SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'Japan';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many customers are from Brazil?,SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'Brazil';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many customers are from India?,SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'India';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many customers are from Spain?,SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'Spain';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many customers are from Italy?,SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'Italy';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the total revenue from 'pending' orders?,SELECT SUM(total_amount) AS revenue FROM orders WHERE status = 'pending';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
List all 'pending' orders with customer name.,"SELECT o.order_id, c.name, o.order_date, o.total_amount
FROM orders o JOIN customers c ON o.customer_id = c.customer_id
WHERE o.status = 'pending';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
What is the total revenue from 'shipped' orders?,SELECT SUM(total_amount) AS revenue FROM orders WHERE status = 'shipped';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
List all 'shipped' orders with customer name.,"SELECT o.order_id, c.name, o.order_date, o.total_amount
FROM orders o JOIN customers c ON o.customer_id = c.customer_id
WHERE o.status = 'shipped';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
What is the total revenue from 'cancelled' orders?,SELECT SUM(total_amount) AS revenue FROM orders WHERE status = 'cancelled';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
List all 'cancelled' orders with customer name.,"SELECT o.order_id, c.name, o.order_date, o.total_amount
FROM orders o JOIN customers c ON o.customer_id = c.customer_id
WHERE o.status = 'cancelled';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
What is the total revenue from 'delivered' orders?,SELECT SUM(total_amount) AS revenue FROM orders WHERE status = 'delivered';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
List all 'delivered' orders with customer name.,"SELECT o.order_id, c.name, o.order_date, o.total_amount
FROM orders o JOIN customers c ON o.customer_id = c.customer_id
WHERE o.status = 'delivered';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
What is the total revenue from 'processing' orders?,SELECT SUM(total_amount) AS revenue FROM orders WHERE status = 'processing';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
List all 'processing' orders with customer name.,"SELECT o.order_id, c.name, o.order_date, o.total_amount
FROM orders o JOIN customers c ON o.customer_id = c.customer_id
WHERE o.status = 'processing';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
How many products are in the 'Electronics' category?,SELECT COUNT(*) FROM products WHERE category = 'Electronics';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the average price of 'Electronics' products?,SELECT AVG(price) AS avg_price FROM products WHERE category = 'Electronics';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the total revenue from 'Electronics' category products?,"SELECT SUM(oi.quantity * oi.unit_price) AS revenue
FROM order_items oi JOIN products p ON oi.product_id = p.product_id
WHERE p.category = 'Electronics';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
How many products are in the 'Clothing' category?,SELECT COUNT(*) FROM products WHERE category = 'Clothing';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the average price of 'Clothing' products?,SELECT AVG(price) AS avg_price FROM products WHERE category = 'Clothing';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the total revenue from 'Clothing' category products?,"SELECT SUM(oi.quantity * oi.unit_price) AS revenue
FROM order_items oi JOIN products p ON oi.product_id = p.product_id
WHERE p.category = 'Clothing';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
How many products are in the 'Books' category?,SELECT COUNT(*) FROM products WHERE category = 'Books';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the average price of 'Books' products?,SELECT AVG(price) AS avg_price FROM products WHERE category = 'Books';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the total revenue from 'Books' category products?,"SELECT SUM(oi.quantity * oi.unit_price) AS revenue
FROM order_items oi JOIN products p ON oi.product_id = p.product_id
WHERE p.category = 'Books';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
How many products are in the 'Sports' category?,SELECT COUNT(*) FROM products WHERE category = 'Sports';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the average price of 'Sports' products?,SELECT AVG(price) AS avg_price FROM products WHERE category = 'Sports';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the total revenue from 'Sports' category products?,"SELECT SUM(oi.quantity * oi.unit_price) AS revenue
FROM order_items oi JOIN products p ON oi.product_id = p.product_id
WHERE p.category = 'Sports';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
How many products are in the 'Home' category?,SELECT COUNT(*) FROM products WHERE category = 'Home';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the average price of 'Home' products?,SELECT AVG(price) AS avg_price FROM products WHERE category = 'Home';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the total revenue from 'Home' category products?,"SELECT SUM(oi.quantity * oi.unit_price) AS revenue
FROM order_items oi JOIN products p ON oi.product_id = p.product_id
WHERE p.category = 'Home';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
How many products are in the 'Beauty' category?,SELECT COUNT(*) FROM products WHERE category = 'Beauty';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the average price of 'Beauty' products?,SELECT AVG(price) AS avg_price FROM products WHERE category = 'Beauty';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the total revenue from 'Beauty' category products?,"SELECT SUM(oi.quantity * oi.unit_price) AS revenue
FROM order_items oi JOIN products p ON oi.product_id = p.product_id
WHERE p.category = 'Beauty';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
What is the total revenue in 2022?,SELECT SUM(total_amount) AS revenue FROM orders WHERE EXTRACT(YEAR FROM order_date) = 2022;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many orders were placed in 2022?,SELECT COUNT(*) AS order_count FROM orders WHERE EXTRACT(YEAR FROM order_date) = 2022;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
Which month had the most orders in 2022?,"SELECT EXTRACT(MONTH FROM order_date) AS month, COUNT(*) AS orders
FROM orders WHERE EXTRACT(YEAR FROM order_date) = 2022
GROUP BY month ORDER BY orders DESC LIMIT 1;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
What is the total revenue in 2023?,SELECT SUM(total_amount) AS revenue FROM orders WHERE EXTRACT(YEAR FROM order_date) = 2023;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many orders were placed in 2023?,SELECT COUNT(*) AS order_count FROM orders WHERE EXTRACT(YEAR FROM order_date) = 2023;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
Which month had the most orders in 2023?,"SELECT EXTRACT(MONTH FROM order_date) AS month, COUNT(*) AS orders
FROM orders WHERE EXTRACT(YEAR FROM order_date) = 2023
GROUP BY month ORDER BY orders DESC LIMIT 1;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
What is the total revenue in 2024?,SELECT SUM(total_amount) AS revenue FROM orders WHERE EXTRACT(YEAR FROM order_date) = 2024;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many orders were placed in 2024?,SELECT COUNT(*) AS order_count FROM orders WHERE EXTRACT(YEAR FROM order_date) = 2024;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
Which month had the most orders in 2024?,"SELECT EXTRACT(MONTH FROM order_date) AS month, COUNT(*) AS orders
FROM orders WHERE EXTRACT(YEAR FROM order_date) = 2024
GROUP BY month ORDER BY orders DESC LIMIT 1;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
List the top 5 best-selling products by total quantity sold.,"SELECT p.name, SUM(oi.quantity) AS total_sold
FROM order_items oi JOIN products p ON oi.product_id = p.product_id
GROUP BY p.name ORDER BY total_sold DESC LIMIT 5;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
Find the average number of items per order.,"SELECT AVG(item_count) AS avg_items_per_order
FROM (SELECT order_id, SUM(quantity) AS item_count FROM order_items GROUP BY order_id) sub;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,subquery
Find the customer who placed the most recent order.,"SELECT c.name, MAX(o.order_date) AS last_order
FROM orders o JOIN customers c ON o.customer_id = c.customer_id
GROUP BY c.customer_id, c.name ORDER BY last_order DESC LIMIT 1;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
What fraction of customers have placed at least one order?,"SELECT ROUND(100.0 * COUNT(DISTINCT o.customer_id) / COUNT(DISTINCT c.customer_id), 2) AS pct_customers_ordered
FROM customers c LEFT JOIN orders o ON c.customer_id = o.customer_id;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,subquery
List the 10 most recent orders with customer name and status.,"SELECT o.order_id, c.name, o.order_date, o.status, o.total_amount
FROM orders o JOIN customers c ON o.customer_id = c.customer_id
ORDER BY o.order_date DESC LIMIT 10;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,join
Which supplier has the highest average product rating via order volume?,"SELECT s.name AS supplier, SUM(oi.quantity) AS units_sold
FROM order_items oi
JOIN products p ON oi.product_id = p.product_id
JOIN suppliers s ON p.supplier_id = s.supplier_id
GROUP BY s.name ORDER BY units_sold DESC LIMIT 1;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,join
Find all orders where the shipping city differs from the customer's city.,"SELECT o.order_id, c.city AS home_city, o.shipping_city
FROM orders o JOIN customers c ON o.customer_id = c.customer_id
WHERE c.city <> o.shipping_city;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
List all products with no sales in the last 60 days.,"SELECT p.name FROM products p
WHERE p.product_id NOT IN (
SELECT DISTINCT oi.product_id FROM order_items oi
JOIN orders o ON oi.order_id = o.order_id
WHERE o.order_date >= CURRENT_DATE - INTERVAL '60 days'
);"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,subquery
How many doctors specialize in Cardiology?,SELECT COUNT(*) FROM doctors WHERE specialty = 'Cardiology';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
List all Cardiology doctors and the hospital they work at.,"SELECT d.name, h.name AS hospital FROM doctors d
JOIN hospitals h ON d.hospital_id = h.hospital_id
WHERE d.specialty = 'Cardiology';"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
What is the average years of experience for Cardiology doctors?,SELECT AVG(years_experience) FROM doctors WHERE specialty = 'Cardiology';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
How many doctors specialize in Neurology?,SELECT COUNT(*) FROM doctors WHERE specialty = 'Neurology';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
List all Neurology doctors and the hospital they work at.,"SELECT d.name, h.name AS hospital FROM doctors d
JOIN hospitals h ON d.hospital_id = h.hospital_id
WHERE d.specialty = 'Neurology';"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
What is the average years of experience for Neurology doctors?,SELECT AVG(years_experience) FROM doctors WHERE specialty = 'Neurology';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
How many doctors specialize in Orthopedics?,SELECT COUNT(*) FROM doctors WHERE specialty = 'Orthopedics';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
List all Orthopedics doctors and the hospital they work at.,"SELECT d.name, h.name AS hospital FROM doctors d
JOIN hospitals h ON d.hospital_id = h.hospital_id
WHERE d.specialty = 'Orthopedics';"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
What is the average years of experience for Orthopedics doctors?,SELECT AVG(years_experience) FROM doctors WHERE specialty = 'Orthopedics';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
How many doctors specialize in Pediatrics?,SELECT COUNT(*) FROM doctors WHERE specialty = 'Pediatrics';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
List all Pediatrics doctors and the hospital they work at.,"SELECT d.name, h.name AS hospital FROM doctors d
JOIN hospitals h ON d.hospital_id = h.hospital_id
WHERE d.specialty = 'Pediatrics';"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
What is the average years of experience for Pediatrics doctors?,SELECT AVG(years_experience) FROM doctors WHERE specialty = 'Pediatrics';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
How many doctors specialize in Oncology?,SELECT COUNT(*) FROM doctors WHERE specialty = 'Oncology';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
List all Oncology doctors and the hospital they work at.,"SELECT d.name, h.name AS hospital FROM doctors d
JOIN hospitals h ON d.hospital_id = h.hospital_id
WHERE d.specialty = 'Oncology';"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
What is the average years of experience for Oncology doctors?,SELECT AVG(years_experience) FROM doctors WHERE specialty = 'Oncology';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
How many doctors specialize in Dermatology?,SELECT COUNT(*) FROM doctors WHERE specialty = 'Dermatology';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
List all Dermatology doctors and the hospital they work at.,"SELECT d.name, h.name AS hospital FROM doctors d
JOIN hospitals h ON d.hospital_id = h.hospital_id
WHERE d.specialty = 'Dermatology';"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
What is the average years of experience for Dermatology doctors?,SELECT AVG(years_experience) FROM doctors WHERE specialty = 'Dermatology';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
How many male patients are there?,SELECT COUNT(*) FROM patients WHERE gender = 'M';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
What is the most common diagnosis among male patients?,"SELECT a.diagnosis, COUNT(*) AS cnt
FROM appointments a JOIN patients p ON a.patient_id = p.patient_id
WHERE p.gender = 'M'
GROUP BY a.diagnosis ORDER BY cnt DESC LIMIT 1;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,aggregate
How many female patients are there?,SELECT COUNT(*) FROM patients WHERE gender = 'F';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
What is the most common diagnosis among female patients?,"SELECT a.diagnosis, COUNT(*) AS cnt
FROM appointments a JOIN patients p ON a.patient_id = p.patient_id
WHERE p.gender = 'F'
GROUP BY a.diagnosis ORDER BY cnt DESC LIMIT 1;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,aggregate
List all patients with 'private' insurance.,SELECT * FROM patients WHERE insurance_type = 'private';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
List all patients with 'public' insurance.,SELECT * FROM patients WHERE insurance_type = 'public';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
List all patients with 'none' insurance.,SELECT * FROM patients WHERE insurance_type = 'none';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
Find the most prescribed medication.,"SELECT medication, COUNT(*) AS prescription_count
FROM prescriptions GROUP BY medication ORDER BY prescription_count DESC LIMIT 1;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
What is the average prescription duration in days?,SELECT AVG(duration_days) AS avg_duration FROM prescriptions;," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
Find patients who have had appointments cancelled more than twice.,"SELECT p.name, COUNT(*) AS cancellations
FROM appointments a JOIN patients p ON a.patient_id = p.patient_id
WHERE a.status = 'cancelled'
GROUP BY p.patient_id, p.name HAVING COUNT(*) > 2;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,aggregate
List all hospitals and the number of doctors they employ.,"SELECT h.name, COUNT(d.doctor_id) AS doctor_count
FROM hospitals h LEFT JOIN doctors d ON h.hospital_id = d.hospital_id
GROUP BY h.name ORDER BY doctor_count DESC;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
Find the doctor who has the most unique patients.,"SELECT d.name, COUNT(DISTINCT a.patient_id) AS unique_patients
FROM doctors d JOIN appointments a ON d.doctor_id = a.doctor_id
GROUP BY d.doctor_id, d.name ORDER BY unique_patients DESC LIMIT 1;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,aggregate
What is the average age of patients at first appointment?,"SELECT AVG(EXTRACT(YEAR FROM AGE(first_appt, p.date_of_birth))) AS avg_age_at_first_appt
FROM patients p
JOIN (
SELECT patient_id, MIN(appointment_date) AS first_appt
FROM appointments GROUP BY patient_id
) fa ON p.patient_id = fa.patient_id;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,subquery
"List prescriptions longer than the average duration, with patient and doctor names.","SELECT pr.medication, pr.duration_days, p.name AS patient, d.name AS doctor
FROM prescriptions pr
JOIN appointments a ON pr.appointment_id = a.appointment_id
JOIN patients p ON a.patient_id = p.patient_id
JOIN doctors d ON a.doctor_id = d.doctor_id
WHERE pr.duration_days > (SELECT AVG(duration_days) FROM prescriptions)
ORDER BY pr.duration_days DESC;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,subquery
Which city has the most patients?,"SELECT city, COUNT(*) AS patient_count FROM patients GROUP BY city ORDER BY patient_count DESC LIMIT 1;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
Show each specialty and the total number of unique patients seen per year.,"SELECT d.specialty, EXTRACT(YEAR FROM a.appointment_date) AS year,
COUNT(DISTINCT a.patient_id) AS unique_patients
FROM appointments a JOIN doctors d ON a.doctor_id = d.doctor_id
GROUP BY d.specialty, year ORDER BY year, unique_patients DESC;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,aggregate
How many users are on the 'free' plan?,SELECT COUNT(*) FROM users WHERE plan = 'free';," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
What is the total revenue from 'free' plan users?,"SELECT SUM(c.revenue) FROM conversions c
JOIN users u ON c.user_id = u.user_id WHERE u.plan = 'free';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,join
How many users are on the 'basic' plan?,SELECT COUNT(*) FROM users WHERE plan = 'basic';," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
What is the total revenue from 'basic' plan users?,"SELECT SUM(c.revenue) FROM conversions c
JOIN users u ON c.user_id = u.user_id WHERE u.plan = 'basic';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,join
How many users are on the 'pro' plan?,SELECT COUNT(*) FROM users WHERE plan = 'pro';," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
What is the total revenue from 'pro' plan users?,"SELECT SUM(c.revenue) FROM conversions c
JOIN users u ON c.user_id = u.user_id WHERE u.plan = 'pro';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,join
How many users are on the 'enterprise' plan?,SELECT COUNT(*) FROM users WHERE plan = 'enterprise';," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
What is the total revenue from 'enterprise' plan users?,"SELECT SUM(c.revenue) FROM conversions c
JOIN users u ON c.user_id = u.user_id WHERE u.plan = 'enterprise';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,join
How many sessions were from mobile?,SELECT COUNT(*) FROM sessions WHERE device = 'mobile';," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
What is the average session duration on mobile?,"SELECT AVG(EXTRACT(EPOCH FROM (end_time - start_time))) AS avg_duration_seconds
FROM sessions WHERE device = 'mobile';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
How many sessions were from desktop?,SELECT COUNT(*) FROM sessions WHERE device = 'desktop';," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
What is the average session duration on desktop?,"SELECT AVG(EXTRACT(EPOCH FROM (end_time - start_time))) AS avg_duration_seconds
FROM sessions WHERE device = 'desktop';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
How many sessions were from tablet?,SELECT COUNT(*) FROM sessions WHERE device = 'tablet';," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
What is the average session duration on tablet?,"SELECT AVG(EXTRACT(EPOCH FROM (end_time - start_time))) AS avg_duration_seconds
FROM sessions WHERE device = 'tablet';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
How many 'page_view' events occurred in the last 30 days?,"SELECT COUNT(*) FROM events
WHERE event_type = 'page_view' AND event_date >= CURRENT_DATE - INTERVAL '30 days';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
How many 'click' events occurred in the last 30 days?,"SELECT COUNT(*) FROM events
WHERE event_type = 'click' AND event_date >= CURRENT_DATE - INTERVAL '30 days';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
How many 'signup' events occurred in the last 30 days?,"SELECT COUNT(*) FROM events
WHERE event_type = 'signup' AND event_date >= CURRENT_DATE - INTERVAL '30 days';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
How many 'purchase' events occurred in the last 30 days?,"SELECT COUNT(*) FROM events
WHERE event_type = 'purchase' AND event_date >= CURRENT_DATE - INTERVAL '30 days';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
How many 'logout' events occurred in the last 30 days?,"SELECT COUNT(*) FROM events
WHERE event_type = 'logout' AND event_date >= CURRENT_DATE - INTERVAL '30 days';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
How many 'search' events occurred in the last 30 days?,"SELECT COUNT(*) FROM events
WHERE event_type = 'search' AND event_date >= CURRENT_DATE - INTERVAL '30 days';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
Find the top 5 most visited pages.,"SELECT page, COUNT(*) AS views FROM events WHERE event_type = 'page_view'
GROUP BY page ORDER BY views DESC LIMIT 5;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
What is the daily active user count for the last 7 days?,"SELECT event_date, COUNT(DISTINCT user_id) AS dau
FROM events
WHERE event_date >= CURRENT_DATE - INTERVAL '7 days'
GROUP BY event_date ORDER BY event_date;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,aggregate
Calculate the 7-day rolling average of daily signups.,"SELECT signup_date, COUNT(*) AS daily_signups,
AVG(COUNT(*)) OVER (ORDER BY signup_date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS rolling_7d_avg
FROM users
GROUP BY signup_date ORDER BY signup_date;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,window
Find users who have not logged any event in the past 30 days.,"SELECT u.user_id, u.username
FROM users u WHERE u.user_id NOT IN (
SELECT DISTINCT user_id FROM events
WHERE event_date >= CURRENT_DATE - INTERVAL '30 days'
);"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,subquery
What is the conversion rate (conversions / total users) per plan?,"SELECT u.plan,
COUNT(DISTINCT c.user_id) AS converters,
COUNT(DISTINCT u.user_id) AS total_users,
ROUND(100.0 * COUNT(DISTINCT c.user_id) / NULLIF(COUNT(DISTINCT u.user_id), 0), 2) AS conversion_rate_pct
FROM users u LEFT JOIN conversions c ON u.user_id = c.user_id
GROUP BY u.plan ORDER BY conversion_rate_pct DESC;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,join
Show sessions that started and ended on different days.,"SELECT * FROM sessions
WHERE DATE(start_time) <> DATE(end_time);"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,select
Find the browser with the highest average session duration.,"SELECT browser,
AVG(EXTRACT(EPOCH FROM (end_time - start_time))) AS avg_sec
FROM sessions GROUP BY browser ORDER BY avg_sec DESC LIMIT 1;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,aggregate
Identify users who made their first conversion within 24 hours of signup.,"WITH first_conv AS (
SELECT user_id, MIN(event_date) AS first_conv_date FROM conversions GROUP BY user_id
)
SELECT u.username, u.signup_date, fc.first_conv_date
FROM users u JOIN first_conv fc ON u.user_id = fc.user_id
WHERE fc.first_conv_date <= u.signup_date + INTERVAL '1 day';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,cte
"Rank users by total revenue generated, partitioned by plan.","SELECT u.username, u.plan, SUM(c.revenue) AS total_revenue,
RANK() OVER (PARTITION BY u.plan ORDER BY SUM(c.revenue) DESC) AS rank_in_plan
FROM users u JOIN conversions c ON u.user_id = c.user_id
GROUP BY u.username, u.plan;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,window
Find all employees with a performance rating of 1.,"SELECT e.name, pr.review_year, pr.bonus
FROM employees e JOIN performance_reviews pr ON e.employee_id = pr.employee_id
WHERE pr.rating = 1;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,join
Find all employees with a performance rating of 2.,"SELECT e.name, pr.review_year, pr.bonus
FROM employees e JOIN performance_reviews pr ON e.employee_id = pr.employee_id
WHERE pr.rating = 2;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,join
Find all employees with a performance rating of 3.,"SELECT e.name, pr.review_year, pr.bonus
FROM employees e JOIN performance_reviews pr ON e.employee_id = pr.employee_id
WHERE pr.rating = 3;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,join
Find all employees with a performance rating of 4.,"SELECT e.name, pr.review_year, pr.bonus
FROM employees e JOIN performance_reviews pr ON e.employee_id = pr.employee_id
WHERE pr.rating = 4;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,join
Find all employees with a performance rating of 5.,"SELECT e.name, pr.review_year, pr.bonus
FROM employees e JOIN performance_reviews pr ON e.employee_id = pr.employee_id
WHERE pr.rating = 5;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,join
What is the average bonus paid in 2022?,SELECT AVG(bonus) FROM performance_reviews WHERE review_year = 2022;," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,aggregate
Which department had the highest average rating in 2022?,"SELECT d.name, AVG(pr.rating) AS avg_rating
FROM performance_reviews pr
JOIN employees e ON pr.employee_id = e.employee_id
JOIN departments d ON e.department_id = d.department_id
WHERE pr.review_year = 2022
GROUP BY d.name ORDER BY avg_rating DESC LIMIT 1;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,aggregate
What is the average bonus paid in 2023?,SELECT AVG(bonus) FROM performance_reviews WHERE review_year = 2023;," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,aggregate
Which department had the highest average rating in 2023?,"SELECT d.name, AVG(pr.rating) AS avg_rating
FROM performance_reviews pr
JOIN employees e ON pr.employee_id = e.employee_id
JOIN departments d ON e.department_id = d.department_id
WHERE pr.review_year = 2023
GROUP BY d.name ORDER BY avg_rating DESC LIMIT 1;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,aggregate
What is the average bonus paid in 2024?,SELECT AVG(bonus) FROM performance_reviews WHERE review_year = 2024;," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,aggregate
Which department had the highest average rating in 2024?,"SELECT d.name, AVG(pr.rating) AS avg_rating
FROM performance_reviews pr
JOIN employees e ON pr.employee_id = e.employee_id
JOIN departments d ON e.department_id = d.department_id
WHERE pr.review_year = 2024
GROUP BY d.name ORDER BY avg_rating DESC LIMIT 1;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,aggregate
Find the employee with the longest tenure.,"SELECT name, hire_date, CURRENT_DATE - hire_date AS tenure_days
FROM employees ORDER BY hire_date ASC LIMIT 1;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,select
List all employees who have never received a bonus.,"SELECT e.name FROM employees e
WHERE e.employee_id NOT IN (
SELECT employee_id FROM performance_reviews WHERE bonus > 0
);"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,subquery
Find departments where every employee earns above 60000.,"SELECT d.name FROM departments d
WHERE NOT EXISTS (
SELECT 1 FROM employees e
WHERE e.department_id = d.department_id AND e.salary <= 60000
);"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,hard,subquery
List the top 3 highest-paid employees per department.,"SELECT department_id, name, salary
FROM (
SELECT department_id, name, salary,
ROW_NUMBER() OVER (PARTITION BY department_id ORDER BY salary DESC) AS rn
FROM employees
) t WHERE rn <= 3;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,hard,window
Find all employees who changed departments in the last year.,"SELECT e.name, e.department_id, e.hire_date
FROM employees e
WHERE e.hire_date >= CURRENT_DATE - INTERVAL '1 year';"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,select
What is the total project budget per department?,"SELECT d.name, SUM(p.budget) AS total_budget
FROM projects p JOIN departments d ON p.department_id = d.department_id
GROUP BY d.name ORDER BY total_budget DESC;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,aggregate
List all projects that are over budget relative to the department budget.,"SELECT p.name AS project_name, p.budget AS project_budget, d.budget AS dept_budget
FROM projects p JOIN departments d ON p.department_id = d.department_id
WHERE p.budget > d.budget;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,join
Find employees assigned to the most hours per week across all projects.,"SELECT e.name, SUM(a.hours_per_week) AS total_hours
FROM employees e JOIN assignments a ON e.employee_id = a.employee_id
GROUP BY e.employee_id, e.name ORDER BY total_hours DESC LIMIT 5;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,aggregate
Calculate year-over-year average bonus change by department.,"WITH dept_bonus AS (
SELECT d.name AS dept, pr.review_year,
AVG(pr.bonus) AS avg_bonus
FROM performance_reviews pr
JOIN employees e ON pr.employee_id = e.employee_id
JOIN departments d ON e.department_id = d.department_id
GROUP BY d.name, pr.review_year
)
SELECT dept, review_year, avg_bonus,
avg_bonus - LAG(avg_bonus) OVER (PARTITION BY dept ORDER BY review_year) AS yoy_change
FROM dept_bonus ORDER BY dept, review_year;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,hard,cte
How many 'receipt' movements happened this month?,"SELECT COUNT(*) FROM movements
WHERE movement_type = 'receipt' AND DATE_TRUNC('month', movement_date) = DATE_TRUNC('month', CURRENT_DATE);"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,aggregate
What is the total quantity moved as 'receipt' this year?,"SELECT SUM(quantity) FROM movements
WHERE movement_type = 'receipt' AND EXTRACT(YEAR FROM movement_date) = EXTRACT(YEAR FROM CURRENT_DATE);"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,aggregate
How many 'shipment' movements happened this month?,"SELECT COUNT(*) FROM movements
WHERE movement_type = 'shipment' AND DATE_TRUNC('month', movement_date) = DATE_TRUNC('month', CURRENT_DATE);"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,aggregate
What is the total quantity moved as 'shipment' this year?,"SELECT SUM(quantity) FROM movements
WHERE movement_type = 'shipment' AND EXTRACT(YEAR FROM movement_date) = EXTRACT(YEAR FROM CURRENT_DATE);"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,aggregate
How many 'adjustment' movements happened this month?,"SELECT COUNT(*) FROM movements
WHERE movement_type = 'adjustment' AND DATE_TRUNC('month', movement_date) = DATE_TRUNC('month', CURRENT_DATE);"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,aggregate
What is the total quantity moved as 'adjustment' this year?,"SELECT SUM(quantity) FROM movements
WHERE movement_type = 'adjustment' AND EXTRACT(YEAR FROM movement_date) = EXTRACT(YEAR FROM CURRENT_DATE);"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,aggregate
How many 'return' movements happened this month?,"SELECT COUNT(*) FROM movements
WHERE movement_type = 'return' AND DATE_TRUNC('month', movement_date) = DATE_TRUNC('month', CURRENT_DATE);"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,aggregate
What is the total quantity moved as 'return' this year?,"SELECT SUM(quantity) FROM movements
WHERE movement_type = 'return' AND EXTRACT(YEAR FROM movement_date) = EXTRACT(YEAR FROM CURRENT_DATE);"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,aggregate
List all items in the 'Raw Materials' category.,SELECT * FROM items WHERE category = 'Raw Materials';," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,select
What is the total stock value for 'Raw Materials' items?,"SELECT SUM(s.quantity * i.unit_cost) AS total_value
FROM stock s JOIN items i ON s.item_id = i.item_id
WHERE i.category = 'Raw Materials';"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,join
List all items in the 'Finished Goods' category.,SELECT * FROM items WHERE category = 'Finished Goods';," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,select
What is the total stock value for 'Finished Goods' items?,"SELECT SUM(s.quantity * i.unit_cost) AS total_value
FROM stock s JOIN items i ON s.item_id = i.item_id
WHERE i.category = 'Finished Goods';"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,join
List all items in the 'Spare Parts' category.,SELECT * FROM items WHERE category = 'Spare Parts';," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,select
What is the total stock value for 'Spare Parts' items?,"SELECT SUM(s.quantity * i.unit_cost) AS total_value
FROM stock s JOIN items i ON s.item_id = i.item_id
WHERE i.category = 'Spare Parts';"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,join
List all items in the 'Packaging' category.,SELECT * FROM items WHERE category = 'Packaging';," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,select
What is the total stock value for 'Packaging' items?,"SELECT SUM(s.quantity * i.unit_cost) AS total_value
FROM stock s JOIN items i ON s.item_id = i.item_id
WHERE i.category = 'Packaging';"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,join
List all items in the 'Consumables' category.,SELECT * FROM items WHERE category = 'Consumables';," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,select
What is the total stock value for 'Consumables' items?,"SELECT SUM(s.quantity * i.unit_cost) AS total_value
FROM stock s JOIN items i ON s.item_id = i.item_id
WHERE i.category = 'Consumables';"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,join
Which warehouse has the highest total stock value?,"SELECT w.name, SUM(s.quantity * i.unit_cost) AS total_value
FROM stock s JOIN items i ON s.item_id = i.item_id
JOIN warehouses w ON s.warehouse_id = w.warehouse_id
GROUP BY w.name ORDER BY total_value DESC LIMIT 1;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,hard,join
Find items that have never had any outbound shipment.,"SELECT i.name FROM items i
WHERE i.item_id NOT IN (
SELECT DISTINCT item_id FROM movements WHERE movement_type = 'shipment'
);"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,hard,subquery
List the top 10 vendors by reliability score.,"SELECT name, reliability_score FROM vendors ORDER BY reliability_score DESC LIMIT 10;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,select
Find items where the on-hand quantity has not changed in the last 90 days.,"SELECT i.name, s.quantity, s.last_updated
FROM stock s JOIN items i ON s.item_id = i.item_id
WHERE s.last_updated < CURRENT_DATE - INTERVAL '90 days';"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,select
Calculate inventory turnover per item (shipments / average stock).,"WITH shipped AS (
SELECT item_id, SUM(quantity) AS total_shipped
FROM movements WHERE movement_type = 'shipment'
GROUP BY item_id
),
avg_stock AS (
SELECT item_id, AVG(quantity) AS avg_qty FROM stock GROUP BY item_id
)
SELECT i.name, s.total_shipped, a.avg_qty,
ROUND(s.total_shipped::numeric / NULLIF(a.avg_qty, 0), 2) AS turnover_ratio
FROM items i
JOIN shipped s ON i.item_id = s.item_id
JOIN avg_stock a ON i.item_id = a.item_id
ORDER BY turnover_ratio DESC;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,hard,cte
Find the vendor with the shortest average lead time.,"SELECT name, lead_time_days FROM vendors ORDER BY lead_time_days ASC LIMIT 1;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,select
Show movements ranked by quantity within each warehouse.,"SELECT w.name AS warehouse, i.name AS item, m.quantity,
RANK() OVER (PARTITION BY m.warehouse_id ORDER BY m.quantity DESC) AS rank_in_warehouse
FROM movements m
JOIN warehouses w ON m.warehouse_id = w.warehouse_id
JOIN items i ON m.item_id = i.item_id;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,hard,window
|