We use HAVING for groups of rows and WHERE for individual rows.
But the following is valid:
SELECT Salesperson, SUM(TotalSale)
FROM SALES
GROUP BY Salesperson
HAVING Salesperson <> 'Georgio';
I.e. use HAVING without an…
I am new to SQL, I want to write a query to find the unique customers to any particular shop.
For example: Shop SH1 is having 10 customers registered, out of 10 - 3 customers also registered to some other shops. I want a query which will return the…
I'm trying to return a list of accounts that are selling a particular product (SourceCustomerProductCode = 102) and want to see accounts that have sold this product in year 2013, but if they sold it in 2012, they I want them excluded from my query…
First -- I have read about 7 pages of posts with similar titles but couldn't find the right insight for my challenge
My SQL:
SELECT name, address, lat, lng, city, state, phone, zip, info
, ( 3959 * acos( cos( radians('37.4969') ) * cos( radians(…
I'm using heroku/ rails/ pgsql 9.1.6 and banging my head against the wall around what feels like it should be a really simple query.
I want to surface recent "Requests" that a user hasn't responded to yet
Attempt 1 (works before I push to heroku/…
Trying to generate a unique code to prevent duplicates i use the following query using HAVING clause so i can use the alias but i get duplicate key errors:
SELECT
FLOOR(100 + RAND() * 899) AS random_code
FROM product_codes
HAVING random_code NOT…
I have two relational tables, person and event_registration, and I would like to select all persons who have registered to 10 or less events. I have found a query which seems to be correct. It can find these persons with the following query:
…
For a website (travel agency) I'm working on performance boosting. At the moment I'm optimizing the search-module. Amongst other things, I want to optimize a select-box which holds a destination. In the system there are several destinations, but not…
I have a query like
SELECT
some_field,
SUM(float_field)
FROM
some_table
GROUP BY
some_field
HAVING
SUM(float_field) <> 0
Is it safe to use such way of comparison in Oracle or it is better to use something…
Following SQL query:
select * from er_101
where cd_relnaam IN (
select cd_relnaam
from er_101
group by cd_relnaam
having count(*) > 1)
AND ld_relopdrachtgever = '1'
Though I need to have that sub query also limits on…
I am using Microsoft SQL Server 2005.
I would like to have a table in output with a column regarding duplicate values in cross join with a table containing only a column with the same string message.
I think the cross join with a "string message"…
I have a query (a view actually) the normally should define a unique mapping from key to value2.
select key, value1, value2
from tbl -- joins are left out here
where (1=1) -- left out here
order by key
;
and usually the result is something like
key…
I want to decorate each member of each repeating group in a table with a sequential number. So for:
id fk scheme code
1 23 2 1234
2 23 2 6666
3 23 2 9876
4 24 2 3421
5 24 5 …
Please click here for sample tables and description.
I have three tables ‘PROJECTS’, 'PROJECTMANAGER' and ‘MANAGERS' as per attached images.
I need a query which can list PROJECTS managed by “PRODUCT” type managers grouped with PROJECT STATUS.
If…
Hi I have following sql statement that gives me the the first_name and total number of jobs all together each employee has done but now I want to have the first_name and job_id of the jobs that an employee has being doing with another worker I have…