Having a number in
Can someone give me a query that will return as a result rows ID 1 & 3? ID Name Hidden 1 Mika 1,4,2 2 Loca 0 3 Nosta 4 4 Like 2 Something like this SELECT * FROM table WHERE Hidden HAVING(4) ...
Can someone give me a query that will return as a result rows ID 1 & 3? ID Name Hidden 1 Mika 1,4,2 2 Loca 0 3 Nosta 4 4 Like 2 Something like this SELECT * FROM table WHERE Hidden HAVING(4) ...
I'm having trouble with Microsoft Access 2003, it's complaining about this statement: select cardnr from change where year(date)<2009 group by cardnr having max(time+date) = (time+date) and cardto='VIP' What I want to do is, for every distinct cardnr in the table change, to find the row with the latest (time+date) that is before year...
See the following SQL statement: SELECT datediff("d", MAX(invoice.date), Now) As Date_Diff , MAX(invoice.date) AS max_invoice_date , customer.number AS customer_number FROM invoice INNER JOIN customer ON invoice.customer_number = customer.number GROUP BY customer.number If the the following was added: HAVIN...
I have a table of 2 tables in a one to many relationship. I want to run an update script that will update the table with the FK of the related table only if there is one result (because if there is multiple then we need to decide which one to use, in another method) Here is what I have so far: UPDATE import_hourly_event_reports i S...
I have a Vendor. Every Vendor has several Reservations, with a ReservationDate on it. I want a list of Vendors that have not made a reservation yet today. In SQL I would do something like this: SELECT v.Id, MAX(r.ReservationDate) AS MaxDate FROM Vendor v INNER JOIN DailyReservation r ON v.Id = r.Vendor_Id GROUP BY v.Id HAVING MAX(r....
Hello. Say there is such table: mysql> SELECT * FROM tags; +---------+--------+ | post_id | tag_id | +---------+--------+ | 1 | 2 | | 1 | 3 | | 1 | 1 | | 2 | 1 | | 2 | 2 | +---------+--------+ 5 rows in set (0.00 sec) Field names are pretty self-explanatory. I want to select post_...
I have a table of users containing the following columns: | User_ID (int) | Name (varchar) | Age (int) | Experience_Level (int) | I would like to create an sql query to output all of the IDs of people who are not unique in the combination of age and experience. My code so far: SELECT Count(*), User_ID FROM Users GROUP BY Age,E...
Hi there, I have the following tables: User :has_many Purchases Item :has_many Purchases Item has a column "amount" (can be + or -) and I need to find all Users that have a positive SUM of "Item.amounts" (over all Purchases each one has made). How does this query look like? (I'm not sure how to handle "SUM" correctly, in this c...
Ok, I have over a million records and I need to select all information from the database where the count of a column is greater or equal to 10. I know that using having I must use group by and using where I cannot use aggregate functions with operators so what I want in pseudo code is Select column1,column2,column3 From MYdatabase Wher...
I'm trying to select duplicates from this table: snr zip 01 83 02 82 03 43 04 28 Expected result is just empty table. Cuz it got no duplicates. I've tried with this query: SELECT snr, zip FROM student GRUOP BY snr HAVING (COUNT(zip) > 1) But it says that syntax is error, and that I'm trying to query an aggregate functions, etc.. ...
I have the the following SQL statement: SELECT [l.LeagueId] AS LeagueId, [l.LeagueName] AS NAME, [lp.PositionId] FROM (Leagues l INNER JOIN Lineups lp ON l.LeagueId = lp.LeagueId) WHERE (lp.PositionId = 1) OR (lp.PositionId = 3) OR (lp.PositionId ...
I have a database with the following schema: ID PositionId LeagueId 1 4 5 3 4 5 3 8 5 4 1 6 I have this sql query in Access: SELECT lp.PositionId FROM Leagues l INNER JOIN Lineups lp ON (l.LeagueID = lp.LeagueId) GROUP BY PositionId HAVING sum(iif(lp...
Urgh...my LINQ has suddenly taken a turn for the worse!! I have two tables and want to join and perform aggregate functions upon the tables. Firstly, is this possible, I am assuming it is, and secondly, how do I handle the aggregate functions? As part of the same LINQ statement? The SQL statement will look a bit like this: SELECT ...
Hi! I'm using entity framework to connect the database. I've a table(Let's call it "File") that haves several fields: ID, Version, XYZ Primarky key is based on ID AND Version. so I can have several line with the same ID but different version(and inversly). The question is: How can I, with a LAMBDA expression, ask my Entity Framewor...
So usually you can just do SELECT COUNT(field.id) FROM table WHERE field.id > 100 and COUNT(field) will return the number of entries that has the criterion of field.id > 100 But then what if you what to count entries specified with the HAVING criterion such as SELECT COUNT(field.id), field.id * 10 AS foo FROM table HAVING foo > 100...