I found this solution online to a HackerRank problem:
SELECT c.hacker_id, h.name, COUNT(c.challenge_id) AS cnt
FROM Hackers AS h
JOIN Challenges AS c ON h.hacker_id = c.hacker_id
GROUP BY c.hacker_id, h.name
HAVING
cnt = (SELECT…
this is the continue question from find out time difference for every user in condition mysql 5.7
this is my fiddle
https://dbfiddle.uk/?rdbms=mysql_5.7&fiddle=31b3be9d1e2444eb0b32c262176aa4b4
i have this table
CREATE TABLE test (
ID INT,
…
SELECT
reservationWH.RNUM AS Reservation,
packageWH.PNAME AS "Package Name",
(COUNT(guestWH.CELL_PHONE) * packageWH.COSTPERSON) AS "Total Cost"
FROM
packageWH
INNER JOIN
reservationWH ON packageWH.P_ID = reservationWH.P_ID…
Using the query below, I can search for properties within a given radius and results are returned.
SELECT id, address, ( 3959 * acos( cos( radians( 53.184815 ) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-3.025741) ) + sin(…
I'm trying to fetch the data with HAVING clause.
Here is my code,
//Main Table
$select->from(array('cre' => 'credit'));
//company Table
$select->join(array('com' => 'company), 'cre.account_id = com.account_id');
$select->join(array('u' => 'user'),…
I've got the following table and I'm trying to retrieve every:
name, descr, stock, address, postalcode & the city
where stock of item1 is > 10 AND stock of item2 is > 10 AND stock of item3 > 5
so I don't want the rows that only contain item1 and…
I have three tables that are all inter-related with the following structure.
ModuleCategory Table:
+------------------+----------------+------------+
| ModuleCategoryID | ModuleCategory | RequireAll…
I'm trying to return a list of map items from my DB grouping the items ONLY if the group count is greater than 4 otherwise I don't want the items to be grouped.
My project is built to return all entries within a set area and I'll be using grouping…
So I don't get this error that I keep getting.
select distinct substr(CUSTZIP, 1,5), AVG(CUSTBAL), custcity, custstate
from customer
group by CUSTCITY, custstate
having CUSTSTATE = 'wa' AND avg(CUSTBAL) >100;
The error says "not a GROUP BY…
I have this table
----------------
ID | Duration
----------------
1 10
2 10
3 10
I want to select the id where sum(duration) becomes greater than 15. In other words...
-------------------------
ID |…
I need to select certain fields for a multipart identifier that has duplicates.
I have the query to grab the duplicates correct.
SELECT b.MemEmpID, b.LastName, b.FirstName
FROM table1 As b
GROUP BY b.MemEmpID,…
From reading the MySQL documentation, I can't explain the difference between these two queries in phpMyAdmin:
SELECT * FROM f_ean GROUP BY ean HAVING type = 'media'
--> gives me 57059 results
SELECT ean, type FROM f_ean GROUP BY ean HAVING type =…
I have 3 tabels with the following definitions
people
------
- wid
- name
types
-----
- guid
- type
mapping
-------
- guid
- wid
The people table has the list of people
The types table the type information for each row present in the people…
I am trying to use some basic SQL functions. I need to get an average of some data and order it in descending order. The error I get is "group function is not allowed"
Table:
STUDENTS
-----------
ID
CLASS
GRADE
ROOM
SQL:
SELECT ID, class,…
I am running the following query and at first it appears to give the sub totals for customers and shows by date each customers payment amounts only if that total for all payments is greater than $90,000.
SELECT
Customername,
…