I have the following table : main(rowId, posDatetime, truckId, lat, lon, address) rowId: PK posDatetime: the date and time of the coordinates and address truckId lat,lon address: address string rows are not fed in datetime order. to get the latest position for each truck I hit the DB with this query FOR EACH …
Tag: sql
How to update a table if values of the attributes are contained within another table?
I’ve got a database like this one: I’m trying to create a query that would enable me to update the value of the status attribute inside the incident table whenever the values of all of these three attributes: tabor_vatrogasci, tabor_policija, and tabor_hitna are contained inside the izvještaj_tabo…
MySQL Error 1264: out of range value for column
As I SET cust_fax in a table in MySQL like this: and then I insert value like this: but then it say `error 1264` out of value for column And I want to know where the error is? My set? Or other? Any answer will be appreciated! Answer The value 3172978990 is greater than 2147483647 – the maximum value for
SELECT id HAVING maximum count of id
Have a products table with item_id and color_id. I’m trying to get the color_id with the most non-null instances. This fails: with This Returns I am looking for color_id 3, which has the most instances. Is there a quick and easy way of getting what I want without 2 queries? Answer This will give you the…
Can’t see MySQL BIT field value when using SELECT
my_table contains the enabled field which is defined as: enabled BIT NOT NULL DEFAULT 0. This table has multiple rows with enabled = b’0′, and multiple rows with enabled = b’1′. However, both this: …
Using a WHERE ___ IN ___ statement
I’m trying to figure out how to properly use a WHERE _ IN _ statement Definition: I’m trying to do something like this: Alternatively, I’ve also tried this, which directly evaluates to the above The error I am getting is: This is giving me an error. When I do it this way, it works, but this …
SELECT query where 1 column equals 2 variables
The issue: I want to select the products which have the option_value_id of both 1 and 3. But, as you can see, it will also show the products which have only have 1 of the option_value_ids. I tried …
Using macros in SAS SQL
I am wondering of I can consolidate some code into one PROC SQL statement instead of several back-to-back SQL statements. I am using macro to calculate the age of a participant at date of consent for a study, similar to what is provided here and here. I tried to troubleshoot the functionality of macros, and I…
MySQL: Count the distinct rows per day
I have an interesting query I need to do. I have a table with an INT column containing ip address numbers (using INET_ATON), and a timestamp column. I want to be able to count the number of unique ip address columns there are per day. That is, how many distinct ip rows there are in each day. So, for example,
PostgreSQL: FOREIGN KEY/ON DELETE CASCADE
I have two tables like here: So the logic is simple, after user removes all book under category x, x gets removed from cats, i tried method above but doesn’t work, after i clean table book, table category still populated, what’s wrong? Answer A foreign key with a cascade delete means that if a rec…