SQL Server group - grouping

I have a sql server database table with columns as shown below :
enter image description here
I want to get an output something like this :enter image description here
I cannot figure out how I can group only zeros listed for EPID and group only ones in my query ? Can anyone point me out how I can solve this ?

Looks like you're trying to query for (EPID=='A' AND isRequired==1) OR EPID=='B', is that right? Here's a guess:
SELECT *
FROM <table>
WHERE (EPID = 'A' AND isRequired = 1)
OR (EPID = 'B');

Related

How to convert this SQL query to Django Queryset?

I have this query which selects values from two different tables and used array agg over matched IDs how can I get same results using the queryset. Thank you!
select
sf.id_s2_users ,
array_agg(sp.id)
from
s2_followers sf
left join s2_post sp on
sp.id_s2_users = sf.id_s2_users1
where
sp.id_s2_post_status = 1
and sf.id_s2_user_status = 1
group by
sf.id_s2_users
You can run raw SQL queries with Django's ORM if that's what you wanted. You don't have to change your query in that case, you can check documentation here.

Show all rows as default in calendar in Oracle Apex

I'm creating a report table type calendar where users can create back up by date select a filter that would filter out the table values depending on the user selected. (i.e. if they choose user1, then only back ups with user1 will show up)
I would like it to be when P106_BACK_UP_BY_USER = 0, the table shows all the values (aka getting rid of the "where" portion of the query.
Thank you for your help!
I'm having issues with trying to allow the user to see all the back ups of the table again (getting rid of the filtered value). My current query is this:
I would like it to be when P106_BACK_UP_BY_USER = 0, the table shows all the values (aka getting rid of the "where" portion of the query.
Thank you for your help!
You can use case when statements in your query's where condition as follows:
select *
from my_table
where my_table.created_by =
(select user_name from my_table2 where app_users_id =
case :P106_BACKUP_BY_USER when 0 then app_users_id
else :P106_BACKUP_BY_USER
end)
And for getting better help, please paste your code as text not as an image next time.
This should work too:
...
WHERE b.active_server = s.server_id
AND (:P106_BACK_UP_BY_USER = 0 OR
UPPER(b.created_by) =
(SELECT UPPER(user_name)
FROM eba_bt_app_users
WHERE app_users_id = :P106_BACK_UP_BY_USER
)
);

QuickSight could not generate any output column after applying transformation Error

I am running a query that works perfectly on AWS Athena however when I use athena as a data source from quicksight and tries to run query it keeps on giving me QuickSight could not generate any output column after applying transformation error message.
Here is my query:
WITH register as (
select created_at as register_time
, serial_number
, node_name
, node_visible_time_name
from table1
where type = 'register'),
bought as (
select created_at as bought_time
, node_name
, serial_number
from table1
where type= 'bought')
SELECT r.node_name
, r.serial_number
, r.register_time
, b.bought_time
, r.node_visible_time_name
FROM register r
LEFT JOIN bought b
ON r.serial_number = b.serial_number
AND r.node_name = b.node_name
AND b.bought_time between r.deploy_time and date(r.deploy_time + INTERVAL '1' DAY)
LIMIT 11;
I've did some search and found similar question Quicksight custom query postgresql functions In this case adding INTERVAL '1' DAY had the problem. I've tried other alternatives but no luck. Furthermore running query without it still outputs same error message.
No other lines seems to be getting transformed in any other way.
Re-creating dataset and running exact same query works.
I think queries that has been ran on existing dataset transforms the data. Please let me know if anyone knows why this is so.

Getting Max count based on Vehid group by Houseid Django

This is the image of the table and output required with details
So, I wrote a Django query
ModelClassName.objects.values('houseid','vehid').annotate(Count('vehid')).order_by('houseid')
This is giving me the count of each vehid but as I am not sure how to incorporate Max here, I am unable to get the right result.
Any help is appreciable.
Thanks.
Create a view to get the counts:
SELECT HOUSEID, VEHID, COUNT(*) FROM TABLE GROUP BY HOUSEID, VEHID
Then query the View
Select Houseid, VEHID, COUNT from MYVIEW A where A.COUNT = (Select Max(B.count) FROM MYVIEW B WHERE A.HOUSEID = B.HOUSEID)
Then you can use Django SQL (https://docs.djangoproject.com/en/2.0/topics/db/sql/) to help you.
(test and let me know if that worked)

Subsonic3 Where "OR" clause linq query

I'm trying to figure out how to do a query with a where blah=blah or blah=blah2 with subsonic 3 linq and I can't figure it out. My query at the moment looks like this:
var ddFaxNumbers = from f in rf_faxnumber.All().Where(f => f.assigned == null).Where(f => f.location == currentFaxNumberRecordData.location)
select f;
This is a page with an update panel where when the user clicks edit I display 2 dropdowns, one for location, and one for the phone numbers. The current phone number is assigned, and marked so in the database table, so when I try to bind the dropdown it throws an error since the results don't contain the currently assigned number. I need to be able to query the table like so:
select * from numbers where assigned == null or number == currentnumber and location=selecteLocation. What I can't figure out in the SS syntax is how to do the OR part of the query. I don't see an .or, so is this even possible? Thanks for your help in advance.
Jon
You should be able to just do:
var ddFaxNumbers = from f in rf_faxnumber.All()
where (f.assigned == null || f.location == currentFaxNumberRecordData.location)
select f;