I am executing this fql query
SELECT status_id,message FROM status WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) order by rand() limit 10
the result I get is just few statuses (about 4), instead of the 10 I asked for, and they are always the same, instead of being random as I asked.
Any advice?
Thank you in advance
SELECT status_id, message
FROM status
WHERE uid IN (
SELECT uid2 LIMIT 10
FROM Friend
WHERE uid=me())
ORDER BY rand()
Related
I have a table like this showing the id of a member, the beginning and end date of their membership, the days of their membership and the gap between their last membership and current membership period.
for example, member 11101 started their membership on 3/1/95 and paused their membership on 11/01/97. they renewed their membership on 6/1/97 without a gap. the total days of this span is 822+153=975 days
he terminated his membership on 11/1/97 and restarted it on 11/10/04. the gap between these two membership are 11/10/04-11/01/97=2565 days
Im trying to find out the longest spans of a certain member's continuous membership, which is 2160 in this case. I think a window function lag/lead is necessary in SQL. however window function is not supported in sql. how can group these periods based on gap days and calculate the max spans?
thank you for the help!
enter image description here
This question was originally tagged SQL/MySQL/Oracle. This answers the original version of the question.
You can summarize the data for each members for a user. The idea is to sum up the non-zero values of gap (which is rather convenient to have). This defines a group that can be used for aggregation. And, in this case, you can just sum the gap:
select id, sum(span), min(begin_date), max(end_date)
from (select t.*,
sum(gap) over (partition by id order by begin_date) as grp
from t
) t
group by id, grp;
For only the longest per id, you can use window functions again:
select *
from (select id, sum(span), min(begin_date), max(end_date),
row_number() over (partition by id order by sum(span) desc) as seqnum
from (select t.*,
sum(gap) over (partition by id order by begin_date) as grp
from t
) t
group by id, grp
) ig
where seqnum = 1;
I am trying to do a left ourter join in Athena and my query looks like the following:
SELECT customer.name, orders.price
FROM customer LEFT OUTER JOIN order
ON customer.id = orders.customer_id
WHERE price IS NULL;
Where each customer could only have one order in the orders table at most and there are customers with no order in the orders table at all. So I am expecting to get some number of records where there is a customer in the customer table with no records in orders table which means when I do LEFT OUTER JOIN the price will be NULL. But this query returns 0 every time I run it. I have queries both tables separately and pretty sure there is data in both but not sure why this is returning zero where it works if I remove the price IS NULL. I have also tried price = '' and price IN ('') and none of them works. Has anyone here had a similar experience before? Or is there something wrong with my query that I can not see or identify?
It seems that your query is correct. To validate, I created two CTEs that should match up with your customer and orders table and ran your query against them. When running the query below, it returns a record for customer 3 Ted Johnson who did not have an order.
WITH customer AS (
SELECT 1 AS id, 'John Doe' AS name
UNION
SELECT 2 AS id, 'Jane Smith' AS name
UNION
SELECT 3 AS id, 'Ted Johnson' AS name
),
orders AS (
SELECT 1 AS customer_id, 20 AS price
UNION
SELECT 2 AS customer_id, 15 AS price
)
SELECT customer.name, orders.price
FROM customer LEFT OUTER JOIN orders
ON customer.id = orders.customer_id
WHERE price IS NULL;
I'd suggest running the following queries:
COUNT(DISTINCT id) FROM customers;
COUNT(DISTINCT customer_id) FROM orders;
Based on the results you are seeing, I would expect those counts to match. Perhaps your system is creating a record in the orders table whenever a customer is created with a price of 0.
Probably you can't use where for order table.
SELECT customer.name, order.price
FROM customer LEFT OUTER JOIN order
ON customer.id = orders.customer_id AND order.price IS NULL;
I am not getting all results which I can see on my timeline in Checkins api and location_post fql. The results returned are very old and can't be sorted.
I have following permission
user_checkin
user_location
friend_checkin
friend_location
Here's an example of all checkins from your friends that have happened in the last 6 months (2678400 seconds in a month).
SELECT author_uid, tagged_uids, target_id, coords, timestamp FROM
checkin WHERE author_uid IN (SELECT uid2 FROM friend WHERE uid1 =
me()) and timestamp > (now() - (2678400*6))
I have a case where I need to count the number of records grouped by publishing year. I've looked at the documentation, and the net in general, but I can't find what to use.
e.g.
2013 = 100 books published
2012 = 95 books
etc..
Using Oracle SQL, this is done using:
select date_published, count(*)
from publications
group by date_published
order by date_published desc
I'm just wondering how to translate this to CFWheels.
Try this:
publications=model("publication").findAll(
select="date_published, COUNT(date_published) AS publishCount"
, group="date_published"
, order="date_published DESC" );
NB, COUNT() is a case-sensitive command in wheels.
PS, or you can do what matt says - you could even attach it to the model so you could do publications.getPubCountByYear() etc.
This is more of a comment, but because I need the formatting I'm posting it as an answer. Can't you write a query just like a regular query in ColdFusion?
<cfquery name="getCounts" datasource="myDSN">
select date_published, count(*)
from publications
group by date_published
order by date_published desc
</cfquery>
I'm developing an facebook application. In this app I get the friends of the user using the graph api. For example:
$facebook->api("/{$user_id}/friends?fields=id,name,gender");
This works fine, but I want to filter to get just the male, or just the female friends. I'm doing this by getting all the friends of the user and then selecting the males or females, but I want to know if there is a way to filter that at the time of the api call. Can someone help me?
Try to use FQL:
/fql?q=select uid, name, sex from user where uid in(select uid2 from friend where uid1 = me()) and sex = "female"
FB dev explorer example